我已将按钮设置为:
CGRect button1Frame = CGRectMake(200, 200, 100, 100);
self.button1 = [[UIButton alloc] initWithFrame:button1Frame];
[self.button1 addTarget:self action:@selector(goToController1:)
forControlEvents:UIControlEventTouchDown];
self.button1.userInteractionEnabled = YES;
self.button1.opaque = YES;
self.button1.backgroundColor = [UIColor redColor];
[self.button1 setTitle:@"B1" forState:UIControlStateNormal];
[self.view addSubview:self.button1];
与我的发件人:
- (void) goToController1:(id)sender {
NSLog(@"Pressed");
}
我的视图控制器已正确初始化。 什么会导致我的按钮不显示?我检查过以确保所有内容都被正确调用。
答案 0 :(得分:5)
你可以试试这个:
button = [UIButton buttonWithType: UIButtonTypeSystem];
然后像这样设置框架:
button.frame = CGRectMake(0,0,20,20);
UIButton buttonWithType:方法一度解决了我的问题。不知道在这种情况下是否会有所作为。只是尝试一下。