iOS 改变UILabel部分颜色


 //协议

    UILabel *xieLabel = [[UILabel alloc] init];

    xieLabel.textColor = TextGrayColor;

    xieLabel.font = [UIFont systemFontOfSize:12];

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"我已阅读并同意《存工资服务协议》"];

    [string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, 7)];

    [string addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(7, string.length - 7)];

    xieLabel.attributedText = string;

    xieLabel.userInteractionEnabled = YES;

    UITapGestureRecognizer *xieyitap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(xiyiAction)];

    [xieLabel addGestureRecognizer:xieyitap];

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM