- iOS 8.0+ / Mac OS X 10.11+ / SnapKit
- Xcode 8.0+
- Swift 3.0+
ELSegmentView
使用SnapKit
设置约束.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let titles = ["日排行","周排行","月排行","总排行"]
let segmentView = ELSegmentView(titles: titles)
view.addSubview(segmentView)
segmentView.snp.makeConstraints { (make) in
make.left.top.right.equalToSuperview()
make.height.equalTo(64)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
满足ELSegmentDelegate
可以响应 button 的点击事件
protocol ELSegmentViewDelegate: class {
func segmentView(_ segmentView: ELSegmentView, didSelectRowAt index: Int)
}
在ViewController
将代理赋给self
segmentView.delegate = self
满足协议
extension ViewController: ELSegmentViewDelegate {
func segmentView(_ segmentView: ELSegmentView, didSelectRowAt index: Int) {
print(index)
}
}
协议提供默认实现