Sha*_*awn 3 objective-c uibutton uiview ios
我已经设置了我的按钮:
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];
Run Code Online (Sandbox Code Playgroud)
与我的发件人:
- (void) goToController1:(id)sender {
NSLog(@"Pressed");
}
Run Code Online (Sandbox Code Playgroud)
我的视图控制器已正确初始化.什么会导致我的按钮不显示?我检查过以确保所有内容都被正确调用.
你可以试试这个:
button = [UIButton buttonWithType: UIButtonTypeSystem];
Run Code Online (Sandbox Code Playgroud)
然后像这样设置框架:
button.frame = CGRectMake(0,0,20,20);
Run Code Online (Sandbox Code Playgroud)
UIButton buttonWithType:方法一度解决了我的问题.不知道在这种情况下是否会有所作为.只是尝试一下.