嗨@user2732294 我已经使用了字符串长度。请检查下面的代码
NSString *needToChangeStr = [[APP_DELEGATE.MuDict_Applied_Language valueForKey:[[NSUserDefaults standardUserDefaults] valueForKey:@"Applied_Language"]] valueForKey:@" Building security system"];
NSString *display_string=[NSString stringWithFormat:@"Test. %@",needToChangeStr];
NSMutableAttributedString *attri_str = [[NSMutableAttributedString alloc]initWithString:display_string];
int begin=[display_string length]-[needToChangeStr length];
int end=[needToChangeStr length];
[attri_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue" size:30] range:NSMakeRange(begin, end)];
[attri_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30] range:NSMakeRange(0, begin)];
// [attri_str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, end)];
[attri_str addAttribute:(id)kCTForegroundColorAttributeName value:[UIColor colorWithRed:35/255 green:86/255 blue:109/255 alpha:1.0] range:NSMakeRange(0, begin)];
[attri_str addAttribute:(id)kCTForegroundColorAttributeName value:[UIColor colorWithRed:44/255 green:92/255 blue:114/255 alpha:1.0] range:NSMakeRange(begin, end)];
// [attri_str addAttribute:(id)kCTForegroundColorAttributeName
// value:(id)[UIColor colorWithRed:31/255 green:68/255 blue:97/255 alpha:1.0].CGColor
// range:NSMakeRange(0, end)];
Label_Center.attributedText = attri_str;