小编Lor*_*ush的帖子

Swift - UIButton重写setSelected

我正在Swift中创建一个UIButton子类,以便在选择时执行自定义绘图和动画

什么在Swift中等同- (void)setSelected:(BOOL)selected于ObjC?

我试过了

override var selected: Bool

所以我可以实现一个观察者,但我得到了

Cannot override with a stored property 'selected'

subclass uibutton ios swift

26
推荐指数
2
解决办法
3万
查看次数

iOS"UITemporaryLayoutHeight"约束

systemLayoutSizeFittingSize用来获得满足其内部约束的自定义视图子类的最小大小.

let someView = SomeView()        
someView.setNeedsUpdateConstraints()
someView.setNeedsLayout()
someView.layoutIfNeeded()

let viewSize = someView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)

println(viewSize) // PRINTS (0.0, 96.0) WHICH IS RIGHT!
Run Code Online (Sandbox Code Playgroud)

我得到正确的值,但我也收到Unable to simultaneously satisfy constraints警告:

"<NSLayoutConstraint:0x7ff16b753190 '_UITemporaryLayoutHeight' V:[ProjectName.SomeView:0x7ff16b772210(0)]>",
"<NSLayoutConstraint:0x7ff16b75de50 UIImageView:0x7ff16b76eff0.top == ProjectName.SomeView:0x7ff16b772210.topMargin>",
"<NSLayoutConstraint:0x7ff16b7653f0 UIImageView:0x7ff16b76eff0.bottom <= ProjectName.SomeView:0x7ff16b772210.bottomMargin>"
Run Code Online (Sandbox Code Playgroud)

下面是我的SomeViewUIView子类.

它只包含固定在顶部,左侧和底部边距的80x80 imageView.(我使用PureLayout编写约束).

现在很明显,这个视图的固定高度为96(边距为80 + 8x2)但理论上如果它的子视图改变了大小,它可以拉伸.

有任何想法吗?搜索谷歌UITemporaryLayoutHeight(或宽度)给出0结果...

class SomeView: UIView {

    let imageView = UIImageView()

    var constraintsSet = false

    override init(frame: CGRect) {

        super.init(frame: frame)

        backgroundColor = UIColor.lightGrayColor()

        imageView.backgroundColor = UIColor.darkGrayColor()
        addSubview(imageView)
    }

    override …
Run Code Online (Sandbox Code Playgroud)

ios autolayout swift

14
推荐指数
3
解决办法
4331
查看次数

标签 统计

ios ×2

swift ×2

autolayout ×1

subclass ×1

uibutton ×1