美文网首页
iOS-改变字符串中指定的字符颜色和大小

iOS-改变字符串中指定的字符颜色和大小

作者: 学_iOS | 来源:发表于2017-07-25 18:18 被阅读264次
self.secondLabel.text = @"0123456789";

NSDictionary *dict = [self titleTextAttributesWithTitleColor:[UIColor redColor] WithTiteleFont:[UIFont systemFontOfSize:23]];

NSMutableAttributedString * tempString = [[NSMutableAttributedString alloc] initWithString: self.secondLabel.text];

 //指定要改变的字符的开始位置和长度     
[tempString addAttributes:dict range:NSMakeRange(6, 4)];

self.secondLabel.attributedText = tempString;
/*
 * 带有字体颜色和字体大小的字典
 */
- (NSMutableDictionary *)titleTextAttributesWithTitleColor:(UIColor *)titleColor WithTiteleFont:(UIFont *)titleFont{

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];

    dict[NSForegroundColorAttributeName] = titleColor;

    dict[NSFontAttributeName] = titleFont;

    return dict;
}

相关文章

网友评论

      本文标题:iOS-改变字符串中指定的字符颜色和大小

      本文链接:https://www.haomeiwen.com/subject/nhkgkxtx.html