您的位置:首页 > 其它

label(也可以说字符串)上不同颜色 和 不同大小 的设置

2016-09-19 14:07 204 查看
UILabel * buyLabel = [[UILabelalloc]
initWithFrame:CGRectMake(10, purchaseBtnY, purchaseBtnW, purchaseBtnH)];

buyLabel.textAlignment =NSTextAlignmentCenter;

buyLabel.font = [UIFontsystemFontOfSize:13.0];

buyLabel.textColor = [UIColorblackColor];

NSString * buyLabelText =
@"我要学习开发求指导,来呀,造作啊";

NSRange range = [buyLabelText
rangeOfString: @"求指导"];

NSMutableAttributedString * str = [[NSMutableAttributedStringalloc]
initWithString:buyLabelText];

[str addAttribute:NSForegroundColorAttributeNamevalue:[UIColor redColor]range:range];

[str
addAttributes:
@{NSForegroundColorAttributeName: [UIColorcyanColor]}range:NSMakeRange(range.location+
range.length, 3)];

[str addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:15]range:range];

buyLabel.attributedText = str;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: