纯代码写iOS
3.代理AppDelegate源文件的didFinishLaunchingWithOptions方法添加代码
4.TestViewController 的viewDidLoad方法
5.添加button的点击事件
6.没了,就这么多
赞0
代码是这里的 http://blog.csdn.net/rorger/article/details/7276484
1.新建一个空视图项目
2.代理AppDelegate头文件声明ViewController
1
|
@property (strong, nonatomic) TestViewController *viewController;
|
1
2
|
self.viewController = [[TestViewController alloc] init];
self.window.rootViewController = self.viewController;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
UIView *contentView = [[UIView alloc]initWithFrame: [[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor lightGrayColor];
self.view = contentView;
// [contentView release];
//label
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 30)];
label.text = @
"PureCode"
;
label.center = contentView.center;
label.backgroundColor = [UIColor lightGrayColor];
label.textAlignment = UITextAlignmentCenter;
[self.view addSubview:label];
// [label release];
//button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(10.0, 20.0, 77, 37)];
[button setTitle:@
"Button"
forState:UIControlStateNormal];
[button setTitle:@
"ok"
forState:UIControlStateDisabled];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
|
1
2
3
4
5
6
7
8
|
- (
void
)buttonPressed:(id)sender{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@
"ButtonPressed"
message:@
"You have pressed the button"
delegate:nil
cancelButtonTitle:@
"Yesh"
otherButtonTitles: nil];
[alert show];
}
|