2023年7月14日发(作者:)
UILabel快速设置⾏间距很久之前在简书上看见过⼀篇类似的⽂章,收藏过,但是时间久了,找不到了,于是⾃⼰记⼀下,避免要⽤的时候⼜找不到了。⼀般都是这么写的UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 300, 0)];oundColor = [UIColor clearColor];OfLines = 0;NSMutableAttributedString* text =[[NSMutableAttributedString alloc]initWithString:string];NSMutableParagraphStyle * paragraphStyle =[[NSMutableParagraphStyle alloc]init];//设置⾏距[paragraphStyle setLineSpacing:15.0f];[text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, )];//设置⼀定Range区间⽂字颜⾊[text addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 30)];//设置⼀定Range区间⽂字下划线[text addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, 30)];utedText = text;[ addSubview:label];[label sizeToFit];简单写法[label setValue:@17 forKey:@"lineSpacing"];注意使⽤的是KVC⽅式,其key为lineSpacing,⽬前在iOS 14中使⽤还有效。
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689264135a226406.html
评论列表(0条)