Swift_TwicketSegmentedControl分段控件使用

Swift_TwicketSegmentedControl分段控件使用

platform :ios,'9.0'
target ‘SwiftDemo’ do
use_frameworks!
inhibit_all_warnings!
pod 'TwicketSegmentedControl'
end

引入

import TwicketSegmentedControl

添加代理

class ViewController: UIViewController,TwicketSegmentedControlDelegate{
 
    var iamgeView : UIImageView!
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        self.view.backgroundColor = UIColor.white
     
        self.iamgeView = UIImageView.init(frame: CGRect.init(x: 0, y: 100, width: 320, height: 160))
        self.iamgeView.image = UIImage.init(named: "1234.jpg")
        self.view.addSubview(self.iamgeView)
       
        let title = ["第一","第二个,"第三个"]
        let frame = CGRect.init(x: 5, y: 40, width: view.frame.width - 10, height: 40)
        let segmentControl = TwicketSegmentedControl.init(frame: frame)
        //设置分段控件各个分段的标题文字
        segmentControl.setSegmentItems(title)
        //设置默认字体颜色为灰色
        segmentControl.defaultTextColor = .gray
         //设置选中字体颜色为白色
        segmentControl.highlightTextColor = .white
        //设置滑块背景颜色为红色
        segmentControl.sliderBackgroundColor = .red
        //设置默认焦点在第几个分段
        segmentControl.move(to: 0)
        //设置代理
        segmentControl.delegate = self
       
       self.view.addSubview(segmentControl)
    }
    func didSelect(_ segmentIndex: Int) {
        if segmentIndex == 0
        {
            self.iamgeView.frame = CGRect.init(x: 0, y: 100, width: 5, height: 5)
        }else{
             self.iamgeView.frame = CGRect.init(x: 0, y: 100, width: 320, height: 160)
        }
    }
}