ios 绘制线框_iOS 各种边框

本文详细介绍了如何在 iOS 中实现各种类型的边框效果,包括实线边框、虚线边框、流动虚线、内边距边框、偏移边框、指定圆角边框以及特殊形状的边框。示例代码清晰,覆盖了多种常见的边框定制需求。
摘要由CSDN通过智能技术生成

UIView *View = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, 100, 100))];

View.center = self.view.center;

[self.view addSubview:View];

View.backgroundColor = [UIColor grayColor];

一、实线边框

实线边框.png

View.layer.borderColor = [UIColor redColor].CGColor;

View.layer.borderWidth = 1;

二、虚线边框

1.虚线边框主要实现是通过增加一个layer绘制一个虚线的矩形,lineDashPattern 第一个参数代表线段长度,第二个参数代表线段间距。

CAShapeLayer *dottedLineBorder = [[CAShapeLayer alloc] init];

dottedLineBorder.frame = CGRectMake(0, 0, View.frame.size.width, View.frame.size.height);

[dottedLineBorder setLineWidth:2];

[dottedLineBorder setStrokeColor:[UIColor redColor].CGColor];

[dottedLineBorder setFillColor:[UIColor clearColor].CGColor];

dottedLineBorder.lineDashPattern = @[@10,@20];//10 - 线段长度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值