1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
class
ViewController
:
UIViewController
{
override
func
viewDidLoad() {
super
.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// 建立一個瀏覽器工具條,並設置它的大小和位置
var
browserToolbar =
UIToolbar
(frame:
CGRectMake
(0, 20, 320, 44))
// 將工具條添加到當前應用的界面中
self
.view.addSubview(browserToolbar)
//建立後退
var
btnback =
UIBarButtonItem
(image:
UIImage
(named:
"back.png"
),
style:
UIBarButtonItemStyle
.
Bordered
, target:
self
,action:
Selector
(
"backClicked:"
));
//第一個分隔按鈕
var
btngap1 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
FlexibleSpace
,
target:
nil
,
action:
nil
);
// 建立前進按鈕 UIBarButtonItem
var
btnforward =
UIBarButtonItem
(image:
UIImage
(named:
"forward.png"
),
style:
UIBarButtonItemStyle
.
Plain
, target:
self
, action:
Selector
(
"forwardClicked:"
));
// 第二個分隔按鈕,建立一個可伸縮的UIBarButtonItem
var
btngap2 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
FlexibleSpace
,
target:
nil
,
action:
nil
);
}
func
backClicked(sender:
UIBarButtonItem
)
{
//後退
}
func
forwardClicked(sender:
UIBarButtonItem
)
{
//前進
}
}
|
1
2
|
var
btnback =
UIBarButtonItem
(image:
UIImage
(named:
"back1.png"
),image:
UIImage
(named:
"back2.png"
),
style:
UIBarButtonItemStyle
.
Bordered
, target:
self
,action:
Selector
(
"backClicked:"
));
|
1
2
|
var
btnback =
UIBarButtonItem
(title:
"肯定"
,
style:
UIBarButtonItemStyle
.
Plain
, target:
self
,action:
Selector
(
"confrim:"
));
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import
UIKit
class
ViewController
:
UIViewController
{
var
pickerView:
UIPickerView
!
override
func
viewDidLoad() {
super
.viewDidLoad()
// 建立一個瀏覽器工具條,並設置它的大小和位置
var
browserToolbar =
UIToolbar
(frame:
CGRectMake
(0, 20, 320, 44))
// 將工具條添加到當前應用的界面中
self
.view.addSubview(browserToolbar)
var
btn1 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
Compose
,
target:
nil
, action:
nil
);
var
btn2 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
Add
,
target:
nil
, action:
nil
);
var
btn3 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
FlexibleSpace
,
target:
nil
, action:
nil
);
var
btn4 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
Reply
,
target:
nil
, action:
nil
);
browserToolbar.setItems([btn1,btn2,btn3,btn4], animated:
false
)
}
}
|
1
2
3
|
var
btngap1 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
FlexibleSpace
,
target:
nil
,
action:
nil
);
|
1
2
3
4
|
var
btngap1 =
UIBarButtonItem
(barButtonSystemItem:
UIBarButtonSystemItem
.
FixedSpace
,
target:
nil
,
action:
nil
);
btngap1.width = 50
|