Can I set the `attributedText` property of `UILabel`

后端 未结 8 917
长发绾君心
长发绾君心 2020-12-22 21:52

Can I set the attributedText property of a UILabel object? I tried the below code:

UILabel *label = [[UILabel alloc] init];
label.a         


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 22:26

    Hope this helps ;)

    NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"asdf"];
    [attrStr setFont:[UIFont systemFontOfSize:12]];
    [attrStr setTextColor:[UIColor grayColor]];
    [attrStr setTextColor:[UIColor redColor] range:NSMakeRange(0,5)];
    lbl.attributedText = attrStr;
    

提交回复
热议问题