自动算 label的高度,自定义各种label(变字体变颜色)

自定义各种label(变字体变颜色)

UILabel* personText=[[UILabelalloc]initWithFrame:CGRectMake(BDRAPPWidth/3, debtMoneyLabel.bottom,BDRAPPWidth/3, debtMoneyLabel.height)];

    [bottomViewaddSubview:personText];

    personText.centerX=debtPersonLabel.centerX;

    NSString* personTextS=[NSStringstringWithFormat:@"%@",[dictobjectForKey:@"debtTotal"]];


    NSString* personString=[NSStringstringWithFormat:@"%@人",personTextS];

    personText.textAlignment=NSTextAlignmentCenter;

    NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:personString];

    [str1addAttribute:NSForegroundColorAttributeName value:HexRGB(colorLong(@"fec967")) range:NSMakeRange(0,personTextS.length)];

    [str1addAttribute:NSForegroundColorAttributeName value:BDRColor_333333 range:NSMakeRange(personTextS.length,1)];

    [str1addAttribute:NSFontAttributeNamevalue:BDR_FONT_BanCu(11)range:NSMakeRange(0,personTextS.length)];

    [str1addAttribute:NSFontAttributeNamevalue:BDR_FONT(11)range:NSMakeRange(personTextS.length,1)];

    personText.attributedText= str1;



自动算 label的高度

UILabel* Label1=[[UILabelalloc]init];

    Label1.frame=CGRectMake(TRUE_(15),0,BDRAPPWidth-TRUE_(30), TRUE_(15));

    Label1.text=[NSStringstringWithFormat:@"申请原因: %@",item.AuthReceiveReason];

    Label1.numberOfLines=0;

    Label1.textColor=BDRColor_333333;

    Label1.font=BDR_FONT(13);


    NSMutableAttributedString * mastring = [[NSMutableAttributedString alloc]initWithString:Label1.text];

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

    [paragraphStylesetLineSpacing:3];//调整行间距


    [mastringaddAttribute:NSParagraphStyleAttributeNamevalue:paragraphStylerange:NSMakeRange(0, mastring.length)];

    [mastringaddAttribute:NSFontAttributeNamevalue:Label1.fontrange:NSMakeRange(0, mastring.length)];



    CGFloatwidth = Label1.width;


    CGRect rect = [mastring boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];


    returnTRUE_(80)+rect.size.height;



从某句话中找到具体的字变颜色

- (NSMutableAttributedString*)searchBlueTextWithAllString:(NSString*)allString withSearchString:(NSString*)searchString

{

    NSString* showLabel = [NSStringstringWithFormat:@"%@",allString];

    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:showLabel];

    NSRangerange;

    //判断字符串中有没有回复

    if([showLabelrangeOfString:searchString].location!=NSNotFound){

        range = [showLabelrangeOfString:searchString];

        [AttributedStraddAttribute:NSForegroundColorAttributeName

                              value:BDRColor_blue

                              range:NSMakeRange(range.location, range.length)];

    }


    returnAttributedStr;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容