程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> iphone-在所有欄中只顯示一個視圖

iphone-在所有欄中只顯示一個視圖

編輯:編程綜合問答
在所有欄中只顯示一個視圖

在UITabViewController的所有欄中只顯示一個視圖(UIButton)。

應該怎麼實現呢?

比如info按鈕在欄中一直顯示,不用將它添加到xib或重寫代碼。

最佳回答:


執行一個Tab Bar Controller類,在viewDidLoad方法中,循環遍歷全部Tab Bar View Controllers添加按鈕。

- (void)viewDidLoad
{
    [super viewDidLoad];
    for(UIViewController *viewController in [self viewControllers]){
        UIButton *infoButton =  [UIButton buttonWithType:UIButtonTypeInfoDark];
        CGRect buttonRect = infoButton.frame;
        // This will place the button 20px away from the top right corner
        buttonRect.origin.x = self.view.frame.size.width - buttonRect.size.width - 20;
        buttonRect.origin.y = 20;
        [infoButton setFrame:buttonRect];
        [infoButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
        [viewController.view addSubview:infoButton];
    }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved