简体   繁体   中英

iOS: Custom button not showing on Storyboard

I am displaying an image programatically in my storyboard and handling successfully landscape/portrait orientation (see code below). I'm trying now to add a custom button on that same view in the storyboard via Interface Builder directly. The button just does not show up when the app runs. Only the image. Could you show me the way to do it on the storyboard view? Or should I add it programatically as well? Or redo everything 100% in Interface builder? Don't really know how to mix and match these 2 methods...

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[self navigationController] setNavigationBarHidden:YES animated:YES];



    UIImage *startImage = [UIImage imageNamed:@"title.png"];
    UIImageView *startImageView = [[UIImageView alloc] initWithImage:startImage];

    self.startImageView = startImageView;

    [self.view addSubview:startImageView];


}

- (void) orientStartImageView
{
     UIInterfaceOrientation curOrientation = [UIApplication sharedApplication].statusBarOrientation;
     if (curOrientation == UIInterfaceOrientationPortrait || curOrientation == UIInterfaceOrientationPortraitUpsideDown) {
     [self.startImageView setFrame:CGRectMake(-128, 0, 1024, 1024)];
 }else{
     [self.startImageView setFrame:CGRectMake(0, -128, 1024, 1024)];
 }
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self orientStartImageView];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    [self orientStartImageView];
}

它的bcoz是在Button的顶部添加ImageView的,您可以使用以下代码将其放在最前面,将其放在viewdidload方法中:

[self.view bringSubviewToFront:yourBtn];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM