效果圖:
atom
@interface XSRecommendedPrivilegeViewController () @property (weak, nonatomic) IBOutlet UIButton *payButton; @property (weak, nonatomic) IBOutlet UILabel *termsLabel;//服務條款 @end @implementation XSRecommendedPrivilegeViewController -(void)viewDidLoad { [super viewDidLoad]; self.payButton.layer.masksToBounds = YES; self.payButton.layer.cornerRadius = 7; NSString * changeString = @"《傾聽者套餐服務條款》"; NSString * termsString = [NSString stringWithFormat:@"點擊下一步表明您贊成%@", changeString]; NSMutableAttributedString * attString = [[NSMutableAttributedString alloc] initWithString:termsString]; NSRange strRange = {[changeString length],[changeString length]};//控制下劃線的開始和結束的範圍 [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];//劃線 [attString addAttributes:@{NSForegroundColorAttributeName:kColor} range:[termsString rangeOfString:changeString]];//改變範圍顏色 [self.termsLabel setAttributedText:attString]; }
//同理改變button的內容 //[_awardDisplayBtn setAttributedTitle:str forState:UIControlStateNormal];