0

Here I used a GZRangeSlider for having a range slider and here i need to give constraints programmatically so that in order to have support for landscape mode can anyone help me how to give programmatically in table view cell ?

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)
    }
Dixit Akabari
  • 2,419
  • 13
  • 26
  • https://stackoverflow.com/questions/36507043/programmatically-creating-constraints-bound-to-view-controller-margins You need to understand constraints. I'd recommend to read the documentation, and also create a another project to test it on Interface Builder, and then you can create them programmatically if needed. – Larme Sep 29 '17 at 08:59

1 Answers1

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])
h.kishan
  • 681
  • 6
  • 20
  • for all the constraints u have set constant value as 0 then how it will set constraints ? –  Sep 29 '17 at 11:17
  • you can change the constant value as per your requirement, i just showed the way to add a constraint to view. Above solution will make rangeSlider same as cell size . – h.kishan Sep 29 '17 at 11:49