美文网首页
UISegmentedControl

UISegmentedControl

作者: CaptainRoy | 来源:发表于2019-08-18 15:16 被阅读0次
class ViewController: UIViewController,UITextFieldDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let items = ["选项一","选项二","选项三"]
        let segmented = UISegmentedControl(items: items)
        segmented.center = self.view.center
        segmented.selectedSegmentIndex = 1
        segmented.tintColor = UIColor.red
        segmented.addTarget(self, action: #selector(segmentedAction(segmented:)), for: .valueChanged)
        self.view.addSubview(segmented)
        
    }
    
    @objc func segmentedAction(segmented:UISegmentedControl) -> Void {
        NSLog("segmented - %d", segmented.selectedSegmentIndex)
    }
    
}
segmented.setTitle("swift", forSegmentAt: 1)
segmented.setImage(UIImage.init(named: ""), forSegmentAt: 2)
segmented.setContentOffset(CGSize.init(width: 10.0, height: 7.0), forSegmentAt: 1)
segmented.insertSegment(withTitle: "Objective-C", at: 4, animated: true)
segmented.insertSegment(with: UIImage.init(named: ""), at: 5, animated: true)
segmented.removeSegment(at: 5, animated: true)

相关文章

网友评论

      本文标题:UISegmentedControl

      本文链接:https://www.haomeiwen.com/subject/dgbrsctx.html