自定义背景导致自定义按钮不显示



我在AppDelegate.m中设置了自定义背景:

[self.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];

在我的视图控制器中,我在将其添加为子视图之前制作了自定义按钮:

- (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];
}

只有我的背景在显示。如果我删除背景 - 按钮出现。

[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];

并且不要忘记扩展名"aButton.png"aButton.jpg"...

为 UIViewController 设置模式或只写一行

[self.View bringSubViewToFront:_button]

相关内容

  • 没有找到相关文章

最新更新