IOS 自訂導覽列

來源:互聯網
上載者:User

標籤:

我們自己建立一個View,來自訂導覽列,如下代碼:

#import <UIKit/UIKit.h>

@interface CustomNavigation : UIView

typedef enum {

    customEventClickLBtn1 ,//點擊了最左邊的按鈕

    customEventClickRBtn1 , //最右邊的按鈕

    customEventClickLBtn2 ,//點擊了左邊第二個按鈕

    customEventClickRBtn2 //點擊了右邊最靠左的按鈕

}CustomEventType;

typedef void(^CustomBlock)(NSInteger indx);

 

/**

 *  設定RootCtrl的Navigation左邊按鈕

 */

- (void)customLeftUserHeadWithItem:(UINavigationItem *)items block:(CustomBlock)block;

 

/**

 *  設定Navigation的title顏色

 *

 *  @param navi 傳遞self.navigationcontroller過來即可

 */

- (void)customNavigationTitle:(UINavigationController *)navi;

 

/**

 *  設定Navigation的返回按鈕為通用的白色返回按鈕

 *

 *  @param navi  傳遞self.navigationitem

 *  @param block 點擊了返回按鈕時需要使用到的

 */

- (void)customNavigationBack:(UINavigationItem *)navi block:(CustomBlock)block;

@end

 

------------------------------.m檔案--------------------------------------------

@implementation CustomNavigation{

    CustomBlock leftBlock;

    CustomBlock rightBlock;

    UINavigationItem *itme;

    UIButton *leftbtn;

}

 

 

- (void)customLeftUserHeadWithItem:(UINavigationItem *)items block:(CustomBlock)block{

    leftBlock = block;

    itme = items;

    UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

    [imgv setImageWithURL:[NSURL URLWithString:[UserModel shareModel].userHead] placeholderImage:IMAGENAMED(@"iconDefultHead")];

    leftbtn = [UIButton buttonWithType:UIButtonTypeCustom];

    [leftbtn setFrame:CGRectMake(0, 0, 80, 40)];

    [leftbtn addSubview:imgv];

    [ViewFastory filletView:imgv];

    [leftbtn addTarget:self action:@selector(clickLeftButton) forControlEvents:UIControlEventTouchUpInside];

 

    itme.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftbtn];

    [leftbtn setUserInteractionEnabled:YES];

}

 

- (void)customNavigationTitle:(UINavigationController *)navi{

    [navi.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont fontWithName:SYSTEMFONTName size:NAV_FONTSize],NSFontAttributeName,nil]];

    [navi.navigationBar setBackgroundImage:IMAGENAMED(@"navigationBg") forBarMetrics:UIBarMetricsDefault];

}

 

- (void)customNavigationBack:(UINavigationItem *)navi block:(CustomBlock)block{

    [self customLeftBtnWithNav:navi imageName:@"iconNavigationBack" block:block];

}

- (void)clickRightButton{

    rightBlock(customEventClickRBtn1);

}

 

- (void)clickMoreButton{

    rightBlock(customEventClickRBtn2);

}

 

- (void)clickLeftButton{

    leftBlock(customEventClickLBtn1);

}

 

- (void)clickTabButton{

    leftBlock(customEventClickLBtn2);

}

 

接下來就是在你需要寫導覽列的介面裡去寫了:

@implementation DetailsTaskCtrl{

    CustomNavigation *customNav;//一定要在這裡定義為屬性哦,不然,你寫的按鈕不會起作用的

}

- (void)loadNav{

   customNav = [CustomNavigation new];

    [customNav customNavigationBack:self.navigationItem block:^(NSInteger index){

      if(index == customEventClickLBtn1){

        [self.navigationController popViewControllerAnimated:YES];

           }

    }];

}

 

今天又被深深的打擊了,來公司一個月了,到現在都還沒有給我簽一份正式的合約,要求的工資也只是個應屆生的工資而已啊.但人事部經理說,公司的檔案裡沒有我.今天有個技術討論會,安卓、IOS的都去了,

我也是IOS的啊,為啥還特意說了下我不用去了.是不是在你沒能力之前,別人的眼都入不了?

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.