Swift爬行篇 UISegmentedControl

前端之家收集整理的这篇文章主要介绍了Swift爬行篇 UISegmentedControl前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

UISegmentedControl

1. 创建

        let appsArray:[String] = ["0","1","2","3","4"]
        let segmented:UISegmentedControl = UISegmentedControl(items: appsArray)
        segmented.frame = CGRectMake(10,310,300,20)
        segmented.selectedSegmentIndex = 0
        self.view.addSubview(segmented)


segmented.selectedSegmentIndex 设置初始化选择


2.重新修改分段卡的显示内容

        let index = segment.selectedSegmentIndex
        TestLable.text = ("第\(index)个")
        segment.setTitle(TestLable.text,forSegmentAtIndex: index)

3. 插入图片

segment.setImage(UIImage(named: "green.png"),forSegmentAtIndex: index)

插入图片标题将会消失,图片标题有且只能显示一个


4.在原有的标题中再插入一个标题

segment.insertSegmentWithTitle(("第\(index+1)个"),atIndex: index,animated: true)
标题将会插入在index的前面


5.获取分段卡的总数


let count = segment.numberOfSegments

6.获取分段卡的内容图片


let title = segment.titleForSegmentAtIndex(index)
let title = segment.imageForSegmentAtIndex(index)

7.点击后是否自动取消选择

segmented.momentary = true
true:自动取消选择 false:不自动取消选择,直到下个title被选中为止

8.边框颜色和背景颜色

segmented.tintColor = UIColor.redColor()
segmented.layer.backgroundColor = UIColor.orangeColor().CGColor


9.使能标题

segment.setEnabled(false,forSegmentAtIndex: index)

10.设置宽度

segment.setWidth(30.0,forSegmentAtIndex: index)


11.移除单个或者所有的标题

    func removeSegmentAtIndex(segment: Int,animated: Bool)
    func removeAllSegments()
原文链接:https://www.f2er.com/swift/326228.html

猜你在找的Swift相关文章