【问题标题】:Minimum size to custom views自定义视图的最小尺寸
【发布时间】:2016-07-07 21:50:54
【问题描述】:

我有一个@IBDesignable 自定义视图。

我想有一个最小高度。

如果我在代码中添加视图,我会覆盖

override init(frame: CGRect) {
    let height = frame.height > minHeight ? minHeight : frame.height
    let minFrame = CGRectMake(frame.origin.x, frame.origin.y, frame.width, height)
    super.init(frame: minFrame)
}

设置最小高度。

在情节提要中添加时

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

被调用。

那么我在哪里可以设置最小高度?

谢谢

【问题讨论】:

    标签: swift uiview


    【解决方案1】:

    你可以像这样添加一个最小高度限制

    var minimumHeightConstraint = NSLayoutConstraint(item: view,
                                                             attribute: .height,
                                                             relatedBy: .greaterThanOrEqual,
                                                             toItem: nil,
                                                             attribute: .notAnAttribute,
                                                             multiplier: 1,
                                                             constant: minHeight)
    

    然后将约束添加到视图的父级

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 2014-03-03
      • 1970-01-01
      相关资源
      最近更新 更多