Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
create NSAttributeString using RE
//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