ios 为一个view添加虚线边框,设置UILabel行间距

2020-12-25  本文已影响0人  缘來諟夢
//虚线边框
    UIView * xxview = [[UIView alloc] initWithFrame:CGRectMake(20, 400, 
    self.view.frame.size.width-40, 80)];
    [self.view addSubview:xxview];
    CAShapeLayer*border=[CAShapeLayer layer];
    border.strokeColor=[UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor;
    border.fillColor=nil;
    border.lineDashPattern=@[@4,@2];
    border.path=[UIBezierPath bezierPathWithRect:xxview.bounds].CGPath;
    border.frame=xxview.bounds;
    [xxview.layer addSublayer:border];
//设置UILabel行间距
NSMutableAttributedString* attrString = [[NSMutableAttributedString  alloc] 
      initWithString:label.text];
 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
 [style setLineSpacing:20];
 [attrString addAttribute:NSParagraphStyleAttributeName value:style 
         range:NSMakeRange(0, label.text.length)];
 label.attributedText = attrString;
//UILabel显示不同颜色字体
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] 
    initWithString:label.text];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] 
      range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] 
     range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] 
    range:NSMakeRange(11,5)];
label.attributedText = string;
上一篇下一篇

猜你喜欢

热点阅读