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 设置初始化选择
let index = segment.selectedSegmentIndex TestLable.text = ("第\(index)个") segment.setTitle(TestLable.text,forSegmentAtIndex: index)
3. 插入图片
segment.setImage(UIImage(named: "green.png"),forSegmentAtIndex: index)
segment.insertSegmentWithTitle(("第\(index+1)个"),atIndex: index,animated: true)该标题将会插入在index的前面
5.获取分段卡的总数
let count = segment.numberOfSegments
let title = segment.titleForSegmentAtIndex(index) let title = segment.imageForSegmentAtIndex(index)
7.点击后是否自动取消选择
segmented.momentary = truetrue:自动取消选择 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)
func removeSegmentAtIndex(segment: Int,animated: Bool) func removeAllSegments()原文链接:https://www.f2er.com/swift/326228.html