TwicketSegmentedControl icon indicating copy to clipboard operation
TwicketSegmentedControl copied to clipboard

Issues with Autolayout and sliderBackgroundColor

Open ajaybeniwal opened this issue 7 years ago • 1 comments

screen shot 2017-02-25 at 6 58 39 pm I am trying to add TwicketSegment Control to my controller but Im facing issues adding to the view with autolayout , it shows and white background strip and the rounded corners come out of the constraints as well

Also setting slider sliderBackgroundColor does not change color for me

import UIKit
import TwicketSegmentedControl
import SnapKit
class PendingActionViewController: UIViewController,TwicketSegmentedControlDelegate {
    var segmentControlView:UIView = {
        var uiView = UIView()
        uiView.backgroundColor =  UIColor.init(red: 0/255.0, green: 102/255.0, blue: 204/255.0, alpha: 1.0)
        return uiView
    }()
    
    var contentView:UIView = {
        var uiView = UIView()
        
        return uiView
        
    }()
    
    var twicketSegmentControl:TwicketSegmentedControl = {
        var twicketSegmentControl : TwicketSegmentedControl = TwicketSegmentedControl(frame:CGRect.zero)
        let titles = ["Messages(4)", "Orders(0)", "Shipments(1)"]
        twicketSegmentControl.setSegmentItems(titles)
        twicketSegmentControl.highlightTextColor = UIColor.white
        twicketSegmentControl.defaultTextColor = UIColor.white
        twicketSegmentControl.sliderBackgroundColor = UIColor.init(red: 26/255.0, green: 153/255.0, blue: 255/255.0, alpha: 1.0)
        twicketSegmentControl.segmentsBackgroundColor = UIColor.red
        return twicketSegmentControl
    }()
    override func viewDidLoad() {
        self.title = "Pending Items"
        super.viewDidLoad()
        configureViewHierarchy()
    }
    
    func configureViewHierarchy(){
        view.addSubview(segmentControlView)
        segmentControlView.snp.makeConstraints { (make) in
            make.top.left.right.equalTo(view)
        }
        
        segmentControlView.addSubview(twicketSegmentControl)
        twicketSegmentControl.delegate = self;
        twicketSegmentControl.snp.makeConstraints { (make) in
            make.top.equalTo(segmentControlView).offset(10)
            make.left.equalTo(segmentControlView).offset(16)
            make.right.equalTo(segmentControlView).offset(-16)
            make.bottom.equalTo(segmentControlView).offset(-10)
            make.height.equalTo(40)
        }
        
        view.addSubview(contentView)
        contentView.snp.makeConstraints { (make) in
            make.left.right.equalTo(view)
            make.bottom.equalTo(view)
            make.top.equalTo(segmentControlView.snp.bottom)
        }

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func didSelect(_ segmentIndex: Int) {
        print("Selected index: \(segmentIndex)")
    }
    

}

ajaybeniwal avatar Feb 25 '17 11:02 ajaybeniwal

I am also having this same issue. It's a shame, this is a great library. Using this with layout constraints is a pain. For some reason the segmented control is extending past the containing view.

ZacharyKhan avatar Oct 28 '18 23:10 ZacharyKhan