Ios 如何使用@IBInspectable属性更改UIButton的大小?
Ios 如何使用@IBInspectable属性更改UIButton的大小?,ios,swift,storyboard,Ios,Swift,Storyboard,ui按钮的我的课程: @IBDesignable class AttributedButton: UIButton { @IBOutlet private var widthLayoutConstraint: NSLayoutConstraint? @IBInspectable override var isSelected: Bool { didSet { widthLayoutConstraint?.constant = isSe
ui按钮的我的课程
:
@IBDesignable class AttributedButton: UIButton {
@IBOutlet private var widthLayoutConstraint: NSLayoutConstraint?
@IBInspectable override var isSelected: Bool {
didSet {
widthLayoutConstraint?.constant = isSelected ? 100 : 50
borderColor = isSelected ? UIColor.lightGray : UIColor.white
}
}
}
然后,当我在情节提要中更改内的宽度为selected
属性时,它就不起作用了。。。为什么?
您确定要在类中添加
widthLayoutConstraint
作为IBOutlet吗?如果按钮是可重用的,那么widthLayoutConstraint
是一个iOutletYes,我确信。。。按钮不可重复使用。。。在UIViewController
中有3个静态按钮…是否有其他方法增加UIButton
的大小?约束是我的想法之一…在尝试玩过之后,似乎编辑按钮的框架不会像它应该的那样出现在故事板上…如果你尝试(或者你想…),改变宽度-例如-`@IBInspectable var width:CGFloat=50.0{didSet{self.frame.size.width=self.width}`,您将需要导航到另一个类并重新打开情节提要以查看更改。