diff --git a/Classes/NSMutableAttributedString+Typeset.h b/Classes/NSMutableAttributedString+Typeset.h index 93fe98a..f0e6e04 100644 --- a/Classes/NSMutableAttributedString+Typeset.h +++ b/Classes/NSMutableAttributedString+Typeset.h @@ -23,6 +23,6 @@ - (NSMutableAttributedString *(^)(NSUInteger))fontSize; - (NSMutableAttributedString *(^)(NSString *))fontName; - (NSMutableAttributedString *(^)(NSString *, CGFloat))font; - +- (NSMutableAttributedString *(^)(UIFont *))exactFont; @end diff --git a/Classes/NSMutableAttributedString+Typeset.m b/Classes/NSMutableAttributedString+Typeset.m index 0842fcd..aefe759 100644 --- a/Classes/NSMutableAttributedString+Typeset.m +++ b/Classes/NSMutableAttributedString+Typeset.m @@ -76,4 +76,10 @@ - (NSMutableAttributedString *)bold { }; } +- (NSMutableAttributedString *(^)(UIFont *))exactFont { + return ^(UIFont *font) { + return self.typeset.exactFont(font).string; + }; +} + @end diff --git a/Classes/NSString+Typeset.h b/Classes/NSString+Typeset.h index c21335b..088f3c6 100644 --- a/Classes/NSString+Typeset.h +++ b/Classes/NSString+Typeset.h @@ -37,5 +37,6 @@ - (NSMutableAttributedString *(^)(NSUInteger))fontSize; - (NSMutableAttributedString *(^)(NSString *))fontName; - (NSMutableAttributedString *(^)(NSString *, CGFloat))font; +- (NSMutableAttributedString *(^)(UIFont *))exactFont; @end diff --git a/Classes/NSString+Typeset.m b/Classes/NSString+Typeset.m index 2fd9a99..8bc5547 100644 --- a/Classes/NSString+Typeset.m +++ b/Classes/NSString+Typeset.m @@ -117,4 +117,10 @@ - (NSMutableAttributedString *)clear { }; } +- (NSMutableAttributedString *(^)(UIFont *))exactFont { + return ^(UIFont *font) { + return self.typeset.exactFont(font).string; + }; +} + @end diff --git a/Classes/TypesetKit.h b/Classes/TypesetKit.h index 7ff774d..6187236 100644 --- a/Classes/TypesetKit.h +++ b/Classes/TypesetKit.h @@ -21,6 +21,7 @@ #define TypesetObjectBlock TypesetBlock(id) #define TypesetColorBlock TypesetBlock(UIColor *) #define TypesetFontBlock TypesetBlock(NSString *, CGFloat) +#define TypesetExactFontBlock TypesetBlock(UIFont *font) #define TypesetMatchBlock TypesetBlock(NSString *, NSStringCompareOptions) #define TSAttributedString(...) _TSAttributedString(metamacro_argcount(__VA_ARGS__), __VA_ARGS__) @@ -37,6 +38,7 @@ NSMutableAttributedString *_TSAttributedString(int size, ...); - (TypesetStringBlock)fontName; - (TypesetCGFloatBlock)fontSize; - (TypesetFontBlock)font; +- (TypesetExactFontBlock)exactFont; - (TypesetKit *)regular; - (TypesetKit *)light; - (TypesetKit *)bold; diff --git a/Classes/TypesetKit.m b/Classes/TypesetKit.m index 89f821d..8754125 100644 --- a/Classes/TypesetKit.m +++ b/Classes/TypesetKit.m @@ -112,6 +112,16 @@ - (TypesetFontBlock)font { }; } +- (TypesetExactFontBlock)exactFont { + return ^(UIFont *font) { + for (NSValue *value in self.attributeRanges) { + NSRange range = [value rangeValue]; + [self.string addAttribute:NSFontAttributeName value:font range:range]; + } + return self; + }; +} + - (TypesetStringBlock)fontName { return ^(NSString *fontName) { if (self.string.length) {