如何以编程方式为rangelider添加约束?

时间:2017-09-29 08:52:48

标签: ios uitableview swift3 constants

这里我使用GZRangeSlider来设置范围滑块,这里我需要以编程方式提供约束,以便为了支持横向模式,任何人都可以帮助我如何在表视图单元格中以编程方式提供吗?

class SliderCell : UITableViewCell {

    var rangeSlider = GZRangeSlider()

    override func awakeFromNib() {
        super.awakeFromNib()
        rangeSlider = GZRangeSlider(frame: CGRect(x:8,y: 60 ,width: self.contentView.bounds.width - 32,height: 30))
        self.addSubview(rangeSlider)
    }

1 个答案:

答案 0 :(得分:0)

    let rangeSliderLeadingConstraint = NSLayoutConstraint(
                                        item: rangeSlider,
                                        attribute: .leading,
                                        relatedBy: .equal,
                                        toItem: self,
                                        attribute: .leading,
                                        multiplier: 1.0,
                                        constant: 0)

    let rangeSliderTrailingConstriant = NSLayoutConstraint(
                                        item: rangeSlider,
                                        attribute: .trailing ,
                                        relatedBy: .equal,
                                        toItem: self,
                                        attribute: .trailing,
                                        multiplier: 1.0,
                                        constant: 0)

    let rangeSliderBottomConstriant = NSLayoutConstraint(
                                        item:,
                                        attribute: .bottom ,
                                        relatedBy: .equal,
                                        toItem: self,
                                        attribute: .bottom,
                                        multiplier: 1.0,
                                        constant: 0)

    let rangeSliderTopConstriant = NSLayoutConstraint(
                                            item: rangeSlider,
                                            attribute: .top ,
                                            relatedBy: .equal,
                                            toItem: self,
                                            attribute: .top,
                                            multiplier: 1.0,
                                            constant: 0)


    self.addConstraints([rangeSliderTopConstriant,rangeSliderBottomConstriant,rangeSliderTrailingConstriant,rangeSliderLeadingConstraint])