[英]Cannot link custom IBDesignable class to UIButton on storyboard
How do I connect IBDesignable custom class to UIButton? 如何将IBDesignable自定义类连接到UIButton?
Code 码
import UIKit
@IBDesignable class MyButton: UIView {
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
}
The name of the file is MyButton.swift
该文件的名称是MyButton.swift
It doesn't show MyButton as the class? 它没有显示MyButton作为类吗? How would I fix this problem? 我该如何解决这个问题?
您可能需要MyButton继承自UIButton,而不是UIView。
You can only link custom classes to objects of the same type, or a type it inherits from. 您只能将自定义类链接到相同类型或继承自其的类型的对象。 Instead of 代替
@IBDesignable class MyButton: UIView {
you probably want 你可能想要
@IBDesignable class MyButton: UIButton {
or link it to a UIView
object instead 或将其链接到UIView
对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.