導(dǎo)航欄和工具欄

屏幕快照 2016-11-28 下午10.57.14.png

1. 導(dǎo)航欄的設(shè)置

首先還是在AppDelegate.m中創(chuàng)建對(duì)象:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2ca2}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s3 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s4 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s5 {font-variant-ligatures: no-common-ligatures; color: #4f8187}span.s6 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}

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

然后在VCRoot中更改導(dǎo)航欄屬性:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Heiti SC Light'; color: #008400}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}span.s1 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s2 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s3 {font-variant-ligatures: no-common-ligatures}span.s4 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s5 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #000000}span.s6 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s7 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures}span.s8 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s9 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s10 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #d12f1b}

    self.view.backgroundColor=[UIColor yellowColor];
    
    //設(shè)置導(dǎo)航欄風(fēng)格顏色
    //UIBarStyleBlack:黑色風(fēng)格肾胯,半透明風(fēng)格
    self.navigationController.navigationBar.barStyle=UIBarStyleBlackOpaque;
    //設(shè)置風(fēng)格為不透明
    self.navigationController.navigationBar.translucent=YES;
    //設(shè)置顏色(設(shè)置后透明度設(shè)置就不起作用了)
    self.navigationController.navigationBar.barTintColor=[UIColor redColor];
    //設(shè)置導(dǎo)航原色項(xiàng)目按鈕的風(fēng)格顏色
    self.navigationController.navigationBar.tintColor=[UIColor greenColor];
    self.title=@"根視圖";
    
    //隱藏導(dǎo)航欄
    //self.navigationController.navigationBar.hidden=YES;
    
    UIBarButtonItem* btn=[[UIBarButtonItem alloc]initWithTitle:@"next" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    self.navigationItem.rightBarButtonItem=btn;
    
屏幕快照 2016-11-28 下午11.21.38.png

2. 工具欄的設(shè)置

還是在VCRoot.m:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Heiti SC Light'; color: #008400}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}span.s1 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #000000}span.s2 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures}span.s4 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s5 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s6 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s7 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s8 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s9 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s10 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures}

 //實(shí)現(xiàn)工具欄對(duì)象
    //默認(rèn)工具欄對(duì)象是隱藏的
    self.navigationController.toolbarHidden=NO;
    
    
    //用三種方法創(chuàng)建三個(gè)工具欄按鈕
    UIBarButtonItem* btn01=[[UIBarButtonItem alloc]initWithTitle:@"left" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    UIBarButtonItem* btn02=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];
    
    UIButton* btnImage=[UIButton buttonWithType:UIButtonTypeCustom];
    [btnImage setImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
    btnImage.frame=CGRectMake(0, 0, 60, 60);
    
    UIBarButtonItem* btn03=[[UIBarButtonItem alloc]initWithCustomView:btnImage];
    
    //固定寬度占位按鈕
    UIBarButtonItem* btnF01=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    btnF01.width=100;
    
    //可變寬度占位按鈕
    //UIBarButtonItem* btnF02=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    
    //按鈕數(shù)組
    NSArray* arrayBtns=[NSArray arrayWithObjects:btn01,btnF01,btn02,btnF01,btn03,nil ];
    
    self.toolbarItems=arrayBtns;

注意

  • 代碼中用了三種不同方法創(chuàng)建工具欄按鈕
  • 調(diào)整工具欄按鈕間隔有兩種方法巡莹,固定寬度占位按鈕和自動(dòng)寬度占位按鈕。
屏幕快照 2016-11-28 下午11.23.53.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末增蹭,一起剝皮案震驚了整個(gè)濱河市砌烁,隨后出現(xiàn)的幾起案子秒梳,更是在濱河造成了極大的恐慌梆砸,老刑警劉巖哺哼,帶你破解...
    沈念sama閱讀 218,122評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件佩抹,死亡現(xiàn)場(chǎng)離奇詭異叼风,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)棍苹,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)无宿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人枢里,你說(shuō)我怎么就攤上這事孽鸡。” “怎么了栏豺?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,491評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵彬碱,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我奥洼,道長(zhǎng)巷疼,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,636評(píng)論 1 293
  • 正文 為了忘掉前任灵奖,我火速辦了婚禮嚼沿,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘桑寨。我一直安慰自己伏尼,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,676評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布尉尾。 她就那樣靜靜地躺著爆阶,像睡著了一般。 火紅的嫁衣襯著肌膚如雪沙咏。 梳的紋絲不亂的頭發(fā)上辨图,一...
    開(kāi)封第一講書(shū)人閱讀 51,541評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音肢藐,去河邊找鬼故河。 笑死,一個(gè)胖子當(dāng)著我的面吹牛吆豹,可吹牛的內(nèi)容都是我干的鱼的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,292評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼痘煤,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼凑阶!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起衷快,我...
    開(kāi)封第一講書(shū)人閱讀 39,211評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤宙橱,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體师郑,經(jīng)...
    沈念sama閱讀 45,655評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡环葵,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,846評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了宝冕。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片张遭。...
    茶點(diǎn)故事閱讀 39,965評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖猬仁,靈堂內(nèi)的尸體忽然破棺而出帝璧,到底是詐尸還是另有隱情,我是刑警寧澤湿刽,帶...
    沈念sama閱讀 35,684評(píng)論 5 347
  • 正文 年R本政府宣布的烁,位于F島的核電站,受9級(jí)特大地震影響诈闺,放射性物質(zhì)發(fā)生泄漏渴庆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,295評(píng)論 3 329
  • 文/蒙蒙 一雅镊、第九天 我趴在偏房一處隱蔽的房頂上張望襟雷。 院中可真熱鬧,春花似錦仁烹、人聲如沸耸弄。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,894評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)计呈。三九已至,卻和暖如春征唬,著一層夾襖步出監(jiān)牢的瞬間捌显,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,012評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工总寒, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留扶歪,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,126評(píng)論 3 370
  • 正文 我出身青樓摄闸,卻偏偏與公主長(zhǎng)得像善镰,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子年枕,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,914評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容