美文网首页
ios 为一个view添加虚线边框,设置UILabel行间距

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

作者: 缘來諟夢 | 来源:发表于2020-12-25 11:03 被阅读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;
    

    相关文章

      网友评论

          本文标题:ios 为一个view添加虚线边框,设置UILabel行间距

          本文链接:https://www.haomeiwen.com/subject/xypxnktx.html