WWSegmentControl 0.2.0

WWSegmentControl 0.2.0

Maintained by William-Weng.



  • By
  • 翁禹斌(William.Weng)

WWSegmentControl

一個自訂有QQ動畫的SegmentControl

Swift 4.0 Version Platform License

一個自訂的SegmentControl (上傳至Cocoapods)

使用範例

IBOutlet

import UIKit
import WWSegmentControl

class ViewController: UIViewController {
    
    @IBOutlet weak var myLabel: UILabel!
    @IBOutlet weak var myUIView: UIView!
    @IBOutlet weak var mySegmentControl: WWSegmentControl!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initWithIBOutlet()
        initWithFrame()
        initWithAutolayout(with: myUIView)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

extension ViewController {
    
    /// 使用IBOutlet
    private func initWithIBOutlet() {
        mySegmentControl.delegate = self
    }
    
    /// 使用Frame
    private func initWithFrame() {
        let mySegmentControl = WWSegmentControl.init(frame: CGRect.init(x: 50, y: 250, width: 200, height: 50))
        mySegmentControl.countSetting(3)
        mySegmentControl.titleSetting(["A", "B", "C"])
        view.addSubview(mySegmentControl)
    }
    
    /// 使用Autolayout
    private func initWithAutolayout(with view: UIView) {
        let mySegmentControl = WWSegmentControl()
        mySegmentControl.countSetting(3)
        mySegmentControl.titleSetting(["", "", ""])
        mySegmentControl.autolayoutSetting(to: view)
    }
}

extension ViewController: WWSegmentControlDelegate {
    
    /// 現在選到哪一個
    func wwSegmentControl(_ wwSegmentControl: WWSegmentControl, selectedItemAt index: Int, for button: UIButton) {
        myLabel.text = button.titleLabel?.text
        print(index)
    }
}