在一个UILabel的文字采用不同的字体样式和字体大小

//标题:红包大厅

        UILabel* tmp_title=[[UILabel alloc] initWithFrame:CGRectMake(0 , 5, max_View.frame.size.width, 24)];

        tmp_title.text=@"进入红包大厅";

        [tmp_title setFont:[UIFont boldSystemFontOfSize:22]];

        [tmp_title setTextColor:[UIColor redColor]];

        [tmp_title setTextAlignment:NSTextAlignmentCenter];

        [self addSubview:tmp_title];

        

        //------------

        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"进入红包大厅"];

        

        NSRange range1=NSMakeRange(0, 6);

        [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];

        [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:10.0] range:NSMakeRange(0, 1)];

        [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14.0] range:NSMakeRange(1, 1)];

        

        [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:18.0] range:NSMakeRange(2, 1)];

        

         tmp_title.attributedText=str;

//显示结果如下图:

这是在同一个UILabel 中显示不同的字体大小,还是比较实用的

原文地址:https://www.cnblogs.com/sugeladi/p/5087937.html