01.
02.
03.
04.
05.
06.
07.
08.
09.#import "ViewController.h"
10.
11.@interface ViewController ()
12.
13.@end
14.
15.@implementation ViewController
16.
17.- (void)viewDidLoad
18.{
19.[super viewDidLoad];
20.
21.
22.UILabel *txt=[[UILabel alloc] initWithFrame:CGRectMake(135,0,100 ,30)];
23.txt.text = @"My Label";
24.txt.textColor = [UIColor blackColor];
25.[[self view] addSubview:txt];
26.
27.[txt release];
28.
29.for(int i = 0; i < 10; i++) {
30.UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
31.[button setFrame:CGRectMake(120, 50 + i*35, 100, 30)];
32.
33.NSMutableString *text= [NSString stringWithFormat:@"Click Me %d",i];
34.
35.[button setTitle:text forState:UIControlStateNormal];
36.[button addTarget:self action:@selector(btnClck) forControlEvents:UIControlEventTouchUpInside];
37.
38.[[self view] addSubview:button];
39.[button release];
40.}
41.}
42.
43.-(void) btnClck {
44.NSLog(@"Button Pressed!");
45.}
46.
47.- (void)didReceiveMemoryWarning
48.{
49.[super didReceiveMemoryWarning];
50.
51.}
52.
53.@end
ไม่มีความคิดเห็น:
แสดงความคิดเห็น