简体   繁体   English

iOS:“自定义”按钮未显示在情节提要上

[英]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. 我现在正尝试通过Interface Builder直接在情节提要中的同一视图上添加自定义按钮。 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? 还是在界面生成器中重做所有内容100%? 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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