iOS虚线,为您的应用增加美感

良好的虚线和圆角视觉效果,会为一个好的app增加美感。iOS虚线,一般是用CAShapeLayer设置其lineWidth、lineDashPattern等属性,然后加载到容器里面,下面是封装好的函数,仅供参考。

- (UIView *)addImaginaryLineWithFrame:(CGRect)frame lineColor:(UIColor *)color lineHeight:(float)height lineDashWidth:(NSNumber *)width lineDashSpace:(NSNumber *)space {
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    
    shapeLayer.position = CGPointMake(0, 1);
    shapeLayer.fillColor = nil;
    
    shapeLayer.strokeColor = color.CGColor;
    shapeLayer.lineWidth = height;
    shapeLayer.lineJoin = kCALineJoinRound;
    shapeLayer.lineDashPattern = @[width, space];
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 0);
    CGPathAddLineToPoint(path, NULL, kScreenWidth - 10,0);
    shapeLayer.path = path;
    CGPathRelease(path);
    
    UIView *view = [[UIView alloc] initWithFrame:frame];
    [view.layer addSublayer:shapeLayer];
    return view;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这家伙睡觉的时候要是咳嗽每次都会吐,今晚忘了克制他晚饭过后不能吃太多东西,结果就悲催了,按照医生的说法要到七周岁以...
    FAB丶花零阅读 72评论 0 0
  • 和两年未见的老友吃了两个多小时的烤肉,滋滋肉香之下毫不尴尬的扯着淡。 伴着几片油亮飘香的雪花牛肉从体重说到变化,工...
    孤独工厂阅读 250评论 0 1
  • 新建项目 composer create-project --prefer-dist --stability=...
    LuckTime阅读 512评论 0 0