####iOS7 Programming Cookbook 第一章学习笔记 UIBarButtonItem
#####Adding Buttons to Navigation Bars Using UIBarButtonItem
1 | - (void) segmentedControlTapped:(UISegmentedControl *)paramSender{ |
##iOS7 Programming Cookbook 第一章学习笔记 UIButton
###Adding Buttons to the User Interface with UIButton1
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
42
43
44
45
46
47
48
49
50- (void) buttonIsPressed:(UIButton *)paramSender{
NSLog(@"Button is pressed.");
}
- (void) buttonIsTapped:(UIButton *)paramSender{
NSLog(@"Button is tapped.");
}
- (void)viewDidLoad{
[super viewDidLoad];
//创建2个UIImage对象
UIImage *normalImage = [UIImage imageNamed:@"NormalBlueButton"];
UIImage *highlightedImage = [UIImage imageNamed:@"HighlightedBlueButton"];
//设置button为自定义
self.myButton = [UIButton buttonWithType:UIButtonTypeCustom];
//坐标
self.myButton.frame = CGRectMake(110.0f,
200.0f,
100.0f,
44.0f);
//设置未按下png
[self.myButton setBackgroundImage:normalImage
forState:UIControlStateNormal];
//设置未按下title
[self.myButton setTitle:@"Normal"
forState:UIControlStateNormal];
//设置按下png
[self.myButton setBackgroundImage:highlightedImage
forState:UIControlStateHighlighted];
//设置按下title
[self.myButton setTitle:@"Pressed"
forState:UIControlStateHighlighted];
//添加按下事件
[self.myButton addTarget:self
action:@selector(buttonIsPressed:)
forControlEvents:UIControlEventTouchDown];
//添加按钮抬起事件
[self.myButton addTarget:self
action:@selector(buttonIsTapped:)
forControlEvents:UIControlEventTouchUpInside];
//添加到view
[self.view addSubview:self.myButton];
}