ios - UIView 的边框填充

标签 ios swift uiview swift4

我在 UIView 周围创建了一个标准边框,如下所示:

 vwGroup.layer.borderColor = UIColor.yellow.cgColor
 vwGroup.layer.borderWidth = 2.0;

但我希望 UIView 和围绕它的边框之间有 5px 的填充/边距/间距。

现在它只是在它周围立即绘制边框。我想将其推出,以便在两者之间留出空隙。

有什么建议吗?我怀疑插入是可行的方法,但无法弄清楚。

谢谢!

最佳答案

Insets 不是要走的路。您使用 inset 从其边距填充 View 的内部内容。对于您需要的最佳选择是将 vwGroup 包装在另一个 UIView 中,并在包装​​ View 中设置边框。像这样的东西:

let wrappingView = UIView(frame: someFrame)
wrappingView.backgroundColor = .clear
wrappingView.layer.borderColor = UIColor.yellow.cgColor
wrappingView.layer.borderWidth = 2.0;
wrappingView.addSubview(vwGroup)

当然,这只是为了让您了解全局。您可能想要设置适当的框架/约束。

关于ios - UIView 的边框填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55014557/

相关文章:

ios - Xcode 收到非 HTTP 200 响应 (400)

ios - 在 iOS 上显示 CVImageBufferRef 的最有效方法是什么

objective-c - 无法在iOS中实现简单的 View 滚动

ios - 在 View Controller View 中渲染/显示可重用 View

ios - 动画边界更改时具有 CALayer 有线效果的自定义 View

ios - 警告 : Incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray<NSString *> * _Nullable'

ios - iOS 12 上不显示图标字体

swift - 如何在 swift 中声明 char *const argv[]

Swift 2.0 GeoCoder 参数列表

swift - 是否可以跟踪面部并在 RealityKit ARView 中渲染它?