我正在我的故事板中以编程方式显示图像并成功处理横向/纵向(请参阅下面的代码)。我现在正尝试通过Interface Builder直接在故事板中的同一视图上添加自定义按钮。应用程序运行时,该按钮不会显示。只有图像。你能告诉我在故事板视图上做到这一点的方法吗?或者我应该以编程方式添加它吗?或者在Interface builder中重做100%的所有内容?真的不知道如何混合和匹配这两种方法...
- (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];
}
答案 0 :(得分:1)
它的bcoz你正在Button上添加ImageView,你可以使用这段代码把它带到前面,把它放在viewdidload
方法中:
[self.view bringSubviewToFront:yourBtn];