Created
July 3, 2017 08:10
-
-
Save masstone-phoenix/0d5b703c3faa3d1205591dbb011d6730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//center | |
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
[paragraphStyle setAlignment:NSTextAlignmentCenter]; | |
//origin string | |
NSString *detail = [NSString stringWithFormat:@"%zd more people .....", [RemoteConfigUtil moreRecentOnlineTotalNumber]]; | |
//attributed string | |
NSMutableAttributedString *attributedDetail = [[NSMutableAttributedString alloc] initWithString:detail | |
attributes:@{NSParagraphStyleAttributeName:paragraphStyle, | |
NSFontAttributeName:[UIFont systemFontOfSize:16], | |
NSForegroundColorAttributeName:RGBCOLOR_HEX(0x333E55)}]; | |
NSRange boldRange = [detail rangeOfString:@"\\d+" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch]; | |
if (boldRange.location != NSNotFound) { | |
[attributedDetail addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16] range:boldRange]; | |
} | |
//UILabel的numberOfLines对它的attributedText属性也有作用 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment