使用 IBInspectable 时,界面构建器如何决定何时引入分隔符
How does the interface builder decide when a separator will be introduced when using IBInspectable
现在我正在创建一个自定义视图,我想知道 interface builder
如何决定何时引入一行。
如您所见,它将它分成 3 个 sub groups
但是我想知道如何确定子组的开始和结束位置。
因为我所做的就是像这样在彼此下面创建 IBInspectables
。
@IBInspectable var dotCount: Int = 0 { didSet { setup() } }
@IBInspectable var dotSize: CGFloat = 7 { didSet { dotSize = dotSize + 1.5 } }
@IBInspectable var dotSpacing: CGFloat = 10
@IBInspectable var dotColor: UIColor = UIColor.clear {
didSet {
for dot in dots {
if let dot = dot, dot != selectedView {
dot.backgroundColor = dotColor
}
}
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
for dot in dots {
if let dot = dot, dot != selectedView {
dot.layer.borderWidth = borderWidth
}
}
}
}
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
for dot in dots {
if let dot = dot, dot != selectedView {
dot.layer.borderColor = borderColor.cgColor
}
}
}
}
@IBInspectable var dotSelectedColor: UIColor = UIColor.black {
didSet {
if let dot = selectedView {
dot.backgroundColor = dotSelectedColor
}
}
}
@IBInspectable var dotSelectedBorderColor: UIColor = UIColor.clear {
didSet {
if let dot = selectedView {
dot.layer.borderColor = dotSelectedBorderColor.cgColor
}
}
}
@IBInspectable var dotSelectedBorderWidth: CGFloat = 0.0 {
didSet {
if let dot = selectedView {
dot.layer.borderWidth = dotSelectedBorderWidth
}
}
}
我很好奇这是如何工作的,因为我相信以某种方式划分元素很有用。
希望有人能告诉我这是如何工作的。
它按名称排序和分隔,因此您无需明确定义分隔线,例如:
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
如您所见,角半径与边框属性分开,因为边框属性具有相同的前缀:Border <subject>
.
现在我正在创建一个自定义视图,我想知道 interface builder
如何决定何时引入一行。
如您所见,它将它分成 3 个 sub groups
但是我想知道如何确定子组的开始和结束位置。
因为我所做的就是像这样在彼此下面创建 IBInspectables
。
@IBInspectable var dotCount: Int = 0 { didSet { setup() } }
@IBInspectable var dotSize: CGFloat = 7 { didSet { dotSize = dotSize + 1.5 } }
@IBInspectable var dotSpacing: CGFloat = 10
@IBInspectable var dotColor: UIColor = UIColor.clear {
didSet {
for dot in dots {
if let dot = dot, dot != selectedView {
dot.backgroundColor = dotColor
}
}
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
for dot in dots {
if let dot = dot, dot != selectedView {
dot.layer.borderWidth = borderWidth
}
}
}
}
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
for dot in dots {
if let dot = dot, dot != selectedView {
dot.layer.borderColor = borderColor.cgColor
}
}
}
}
@IBInspectable var dotSelectedColor: UIColor = UIColor.black {
didSet {
if let dot = selectedView {
dot.backgroundColor = dotSelectedColor
}
}
}
@IBInspectable var dotSelectedBorderColor: UIColor = UIColor.clear {
didSet {
if let dot = selectedView {
dot.layer.borderColor = dotSelectedBorderColor.cgColor
}
}
}
@IBInspectable var dotSelectedBorderWidth: CGFloat = 0.0 {
didSet {
if let dot = selectedView {
dot.layer.borderWidth = dotSelectedBorderWidth
}
}
}
我很好奇这是如何工作的,因为我相信以某种方式划分元素很有用。
希望有人能告诉我这是如何工作的。
它按名称排序和分隔,因此您无需明确定义分隔线,例如:
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
如您所见,角半径与边框属性分开,因为边框属性具有相同的前缀:Border <subject>
.