1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import
UIKit
class
ViewController
:
UIViewController
{
override
func
viewDidLoad() {
super
.viewDidLoad()
let
items=[
"选项一"
,
"选项二"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
UIImage
(named:
"star"
)!]
as
[
AnyObject
]
segmented=
UISegmentedControl
(items:items)
segmented.center=
self
.view.center
segmented.selectedSegmentIndex=1
//默认选中第二项
segmented.addTarget(
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,action:
"segmentDidchange:"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
.view.addSubview(segmented)
}
segmentDidchange(segmented:
){
//获得选项的索引
print
(segmented.selectedSegmentIndex)
//获得选择的文字
(segmented.titleForSegmentAtIndex(segmented.selectedSegmentIndex))
}
}
|
//添加文字选项
segmented.insertSegmentWithTitle(
"新增选项"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,atIndex:1,animated:
true
);
segmented.insertSegmentWithImage(
"icon"
)!,monospace!important; min-height:inherit!important">)
//移除选项
segmented.removeSegmentAtIndex(1,monospace!important; min-height:inherit!important">);
|