Custom background resulting in custom button not showing

63 views Asked by At

I set my custom background in my AppDelegate.m:

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

And in my viewcontroller i make my custom button before adding it as a subview:

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

}

Only my background is showing. If I remove the background - the button appears.

2

There are 2 answers

0
kshitij godara On

Set a pattern for UIViewController or just write a line

[self.View bringSubViewToFront:_button]
1
user3110923 On
[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];

And do not forget the extention "aButton.png" "aButton.jpg"...