ios - UIView 周围的虚线边框

如何在 UIView 周围添加虚线边框。

类似的东西

最佳答案

如果你喜欢子层,另一种方法。在自定义 View 的 init 中,输入以下内容(_border 是 ivar):

_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];
[self.layer addSublayer:_border];

在你的布局 subview 中,放这个:

_border.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
_border.frame = self.bounds;

https://stackoverflow.com/questions/13679923/

相关文章:

objective-c - NSInvocation 傻瓜?

ios - 使用 AVFoundation AVPlayer 循环播放视频?

ios - 自定义 UITableView 标题部分

ios - 以编程方式调用电话

iphone - 如何在 Objective-C 2.0 中将方法标记为已弃用?

ios - 较小时 UIScrollView 的中心内容

objective-c - Objective-C 中是否存在强类型集合?

objective-c - Objective-C 中可为空、__nullable 和 _Nulla

objective-c - 在 Objective-C 中大写或更改 NSString 的大小写

objective-c - 在objective-c中@符号代表什么?