ios - UIView 周围的虚线边框

标签 ios objective-c iphone 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;

关于ios - UIView 周围的虚线边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13679923/

相关文章:

ios - 在 SpriteKit 中保存一个关卡编号

objective-c - 更改选择上的标签。 UIPickverView

iphone - 用 Quartz 2D 绘制中文字体字形?

iphone - 如何更改名为的 UIView 的后退按钮标题?

ios - Em 字体大小不会在 iOS 中按比例放大

ios - 构建成功后将文本文件安装/导入到物理设备时 Xcode 崩溃 (RangeException)

iphone - 内置点赞按钮 - Facebook SDK 3.0

android - 这是一个错误吗?点击一个元素会导致另一个元素接收键盘焦点

ios - 如何引用在 Storyboard 中创建的日期选择器并为其赋予默认值?

ios - 如何在没有SDK的情况下在iOS中集成Linkedin登录?