可自訂導航條功能案例ios項目源碼

來源:互聯網
上載者:User

標籤:http   io   ar   color   os   使用   sp   for   檔案   

可定製的navigationitem ,當我們使用系統的方法設定navigationItem的leftItem或者rightItem時,我們會 發現item位置會有偏差(左邊的偏右,右邊的偏左)。當設定navigationItem的titleView時, 會發現圖片被展開。因此我對系統的設定方法做了一個簡單的封裝,可以方便的設定navigationItem 的leftItem,titleView,rightItem並可以自主控制item的位移量。 


  • <ignore_js_op> 


使用方法:


一、將demo裡的customBarItem檔案夾加入工程。 

二、在要設定的檔案裡加入標頭檔#import "UINavigationItem+CustomItem.h" 

三、設定 

1、通過文字設定item 
[self.navigationItem setItemWithTitle:@"自訂item" textColor:[UIColor redColor] fontSize:16 itemType:center]; 
    參數說明:①、文字內容 ②、文字顏色 ③、字型大小  
     ④、item的格式 left對應leftItem  center對應titleView   right對應rightItem 

2、通過圖片設定item 
[self.navigationItem setItemWithImage:@"test1.png" size:CGSizeMake(48/2, 26/2) itemType:left]; 
    參數說明:①、圖片名稱 ②、圖片尺寸 ③、同上 

3、為item添加點擊事件 
     1、2兩種設定方法均會返回一個CustomBarItem執行個體,獲得這個執行個體進行事件添加: 
     CustomBarItem *rightItem = [self.navigationItem setItemWithImage:@"test.png" size:CGSizeMake(39/2, 40/2) itemType:right]; 
    [rightItem addTarget:self selector:@selector(search) event:(UIControlEventTouchUpInside)]; 

4、設定item位移量 
同3先拿到CustomBarItem執行個體然後進行設定 
[rightItem setOffset:10];//數值越大,則leftItem越靠左  rightItem越靠右  預設值為10 

5、當用文字設定item時設定item的尺寸 
[rightItem setTitleViewSize:CGSizeMake(width, height)]; 

 

詳細說明:http://ios.662p.com/thread-2294-1-1.html

可自訂導航條功能案例ios項目源碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.