UIButton如果用alloc init创建,是没法正常显示使用的
下面这种方法是错误的
UIButton* btn=[UIbutton alloc]init];
btn.frame=CGRectMake(100, 100, 100, 30);
[btn addTarget:self action:@selector(pressBtn) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"press" forState:UIControlStateNormal];
[btn setTitle:@"pressDown" forState:UIControlStateHighlighted];
[self.view addSubview:btn];
正确创建UIButton的方法
UIButton* btn=[UIButton buttonWithType:UIButtonTypeSystem];
btn.frame=CGRectMake(100, 100, 100, 30);
[btn addTarget:self action:@selector(pressBtn) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"press" forState:UIControlStateNormal];
[btn setTitle:@"pressDown" forState:UIControlStateHighlighted];
[self.view addSubview:btn];
记录自己走过的弯路