iOS開發 OC 導覽列 UINavigationController 工具條 UIToolBar

來源:互聯網
上載者:User

標籤:

導覽列最常見的例子就是返回按鈕的所在

在AppDelegate.m中,代碼布局最開始定義視窗的時候, _window.rootViewController就應該為一個UINavigationController

這裡的UINavigationController,戳進定義發現它是UIViewcontroller的子類

而之前代碼布局中這裡用的rootController是UIViewcontroller

所以它之中也是像之前代碼布局中的UIViewcontroller一樣是包含多個controller的,所以作為rootController

//按我自己理解,UINavigationController就是一個帶導覽列的特殊UIViewcontroller,我們用導覽列,就選擇用它

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc]init]]; _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; _window.rootViewController = rootNav; [_window makeKeyAndVisible]; return YES;}

導覽列暫時完成,下面去定義工具條

 建立一個View,父類選擇UIToolBar,這就是我們自己的工具條View

 

 

ToolBar作為一個獨立的View,和之前的代碼布局中我們自己的Mainview沒什麼區別,想添加控制項的方法都是一樣的

只不過這個ToolBar只是一個工具列,所以定位只在工具列的一塊小地區中定位,這是差不多唯一的不同

 

現在,我們要載入的有我們本身想要的一個View,通過改變rootController類型添加了導覽列,現在我們又要添加導航條,要載入的就不止一個View

在上次單純的代碼布局中,在Viewcontroller.m中重寫的loadView是這樣的

-(void)loadView {     self.view = [[MainView alloc]initWithFrame:[UIScreen mainScreen].bounds]; }

 

直接把定義的根view賦值了我們自己的Mainview這一個,現在我們需要多個,就可以

-(void)loadView{    [self.navigationItem setTitle:@"備忘錄"];    [super loadView];    [self.view addSubview:[[NoteListView alloc]                           initWithFrame:[UIScreen mainScreen].bounds                           style:UITableViewStylePlain]];    [self.view addSubview:[[NoteListToolbar alloc]                           initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 44, [UIScreen mainScreen].bounds.size.width, 44)]];}

 

先調用父類的loadView , [super loadView],來保證我們有一個基本的View存在,雖然他是空的,表示為黑屏

接著可以向這個View中使用addSubview添加你想要的View

另外這裡的self是最開始的rootController的類型UINavigationController,使用它的屬性來定義了標題

 

iOS開發 OC 導覽列 UINavigationController 工具條 UIToolBar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.