カスタムUIButton
4285 ワード
1 // ButtonViewController.m :
2
3 - (void)viewDidLoad {
4
5 [super viewDidLoad];
6
7 //
8 UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
9
10
11 //
12 [sampleButton setFrame:CGRectMake(10, 100, self.view.bounds.size.width- 20, 52)];
13
14 //
15 [sampleButton setTitle:@"Button Title" forState:UIControlStateNormal];
16
17 //
18 [sampleButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
19
20 // ,redButton.png , image
21 [sampleButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"]stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
22
23 //
24 [sampleButton addTarget:self action:@selector(buttonClicked)forControlEvents:UIControlEventTouchUpInside];
25
26 // View
27 [self.viewaddSubview:sampleButton];
28
29
30 }
31
32 //
33
34 -(void) buttonClicked {
35
36 }