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

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;


你可能感兴趣的:(label(也可以说字符串)上不同颜色 和 不同大小 的设置)