Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set an exact UIFont #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/NSMutableAttributedString+Typeset.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
- (NSMutableAttributedString *(^)(NSUInteger))fontSize;
- (NSMutableAttributedString *(^)(NSString *))fontName;
- (NSMutableAttributedString *(^)(NSString *, CGFloat))font;

- (NSMutableAttributedString *(^)(UIFont *))exactFont;

@end
6 changes: 6 additions & 0 deletions Classes/NSMutableAttributedString+Typeset.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ - (NSMutableAttributedString *)bold {
};
}

- (NSMutableAttributedString *(^)(UIFont *))exactFont {
return ^(UIFont *font) {
return self.typeset.exactFont(font).string;
};
}

@end
1 change: 1 addition & 0 deletions Classes/NSString+Typeset.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
- (NSMutableAttributedString *(^)(NSUInteger))fontSize;
- (NSMutableAttributedString *(^)(NSString *))fontName;
- (NSMutableAttributedString *(^)(NSString *, CGFloat))font;
- (NSMutableAttributedString *(^)(UIFont *))exactFont;

@end
6 changes: 6 additions & 0 deletions Classes/NSString+Typeset.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ - (NSMutableAttributedString *)clear {
};
}

- (NSMutableAttributedString *(^)(UIFont *))exactFont {
return ^(UIFont *font) {
return self.typeset.exactFont(font).string;
};
}

@end
2 changes: 2 additions & 0 deletions Classes/TypesetKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -37,6 +38,7 @@ NSMutableAttributedString *_TSAttributedString(int size, ...);
- (TypesetStringBlock)fontName;
- (TypesetCGFloatBlock)fontSize;
- (TypesetFontBlock)font;
- (TypesetExactFontBlock)exactFont;
- (TypesetKit *)regular;
- (TypesetKit *)light;
- (TypesetKit *)bold;
Expand Down
10 changes: 10 additions & 0 deletions Classes/TypesetKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down