iOS 画线

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

推荐阅读更多精彩内容

  • 1.块级元素和行内元素 块级(block-level)元素;行内(内联、inline-level)元素。 块元素的...
    饥人谷_小侯阅读 6,185评论 1 4
  • 转载:http://www.jianshu.com/p/32fcadd12108 每个UIView有一个伙伴称为l...
    F麦子阅读 11,501评论 0 13
  • 每个UIView有一个伙伴称为layer,一个CALayer。UIView实际上并没有把自己画到屏幕上;它绘制本身...
    shenzhenboy阅读 8,316评论 0 17
  • 莫泊桑的短篇小说《巴蒂斯特太太》里,丰塔内尔小姐在11岁的时候被叫巴蒂斯特的男仆玷污,虽然男仆被判处终生服苦役,但...
    周橙栀阅读 3,831评论 1 3
  • 今天的生活源于三年前的抉择,三年后的生活取决于你今天的定位。想过上什么样的生活,需要靠自己的努力,也要学会“靠”别...
    陶壹阅读 825评论 0 2