美文网首页
iOS 画线

iOS 画线

作者: 小鹏学长168 | 来源:发表于2017-02-15 15:56 被阅读402次

    1.iOS画虚线边框layer.border

    // 给self.view画一个类似self.layer.border的虚线边框
    CAShapeLayer *border = [CAShapeLayer layer];
    border.strokeColor = SLColorLine.CGColor;
    border.fillColor = nil;
    border.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
    border.frame = self.bounds;
    border.lineWidth = 1.f;
    border.lineCap = @"square";
    border.lineDashPattern = @[@4, @2];
    [self.layer addSublayer:border];
    

    2.iOS画小于1px的细线

    CALayer *layer = view.layer;
    layer.borderColor = [UIColor whiteColor].CGColor;
    layer.borderWidth = (1.0 / [UIScreen mainScreen].scale / 2);
    

    3.iOS 设置行距,并且计算有行距的文本高度

     [text addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, text.length)];
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            
            [paragraphStyle setLineSpacing:5];//调整行间距
            
            [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
        
    [self.topicDeatil.article.content boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]  ,NSParagraphStyleAttributeName : paragraphStyle} context:nil].size.height ;
    

    相关文章

      网友评论

          本文标题: iOS 画线

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