zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

iOS 改变UILabel部分颜色

ios 部分 改变 颜色 UILabel
2023-09-27 14:21:33 时间

 //协议

    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];