我在AppDelegate.m
:
[self.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];
在我的viewcontroller中,我将自定义按钮添加为子视图:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.mainButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.mainButton setImage:[UIImage imageNamed:@"aButton"] forState:UIControlStateNormal];
[self.mainButton setImage:[UIImage imageNamed:@"aButton"] forState:UIControlStateHighlighted];
[self.mainButton setFrame:CGRectMake(100, 100, 300, 100)];
[self.view addSubview:self.mainButton];
}
只显示我的背景。如果我删除背景 - 按钮出现。
答案 0 :(得分:0)
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"aButton"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"aButton"] forState:UIControlStateHighlighted];
[button setFrame:CGRectMake(100, 100, 300, 100)];
[self.view addSubview:button];
不要忘记扩展名“Button.png”“aButton.jpg”......
答案 1 :(得分:0)
为UIViewController设置模式或只写一行
[self.View bringSubViewToFront:_button]