[英]iOS: Custom button not showing on Storyboard
我正在故事板上以編程方式顯示圖像,並成功處理了橫向/縱向方向(請參見下面的代碼)。 我現在正嘗試通過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];
}
它的bcoz是在Button的頂部添加ImageView的,您可以使用以下代碼將其放在最前面,將其放在viewdidload
方法中:
[self.view bringSubviewToFront:yourBtn];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.