Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用@IBInspectable属性更改UIButton的大小?_Ios_Swift_Storyboard - Fatal编程技术网

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}`,您将需要导航到另一个类并重新打开情节提要以查看更改。