Sealyu

          --- 博客已遷移至: http://www.sealyu.com/blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
          在實際的開發中,導航器是最重要的容器之一,我們經常要在導航欄中添加各種樣式的按鈕,添加一個按鈕很簡單,代碼如下圖: UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTi

          在實際的開發中,導航器是最重要的容器之一,我們經常要在導航欄中添加各種樣式的按鈕,添加一個按鈕很簡單,代碼如下圖:

          UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Setting" style:UITabBarSystemItemContacts
                                                                           target:self action:@selector(clickSettings:)];         
          self.navigationItem.rightBarButtonItem = anotherButton;
          [anotherButton release];

          其中按鈕的樣式可以有多種,具體的可以參考:https://developer.apple.com/library/ios/prerelease/#documentation/UIKit/Reference/UIBarButtonItem_Class/

          在有些項目中要在右面添加兩個按鈕,實現的樣式如下圖:

           

           

          實現的代碼如下圖:

          UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)];
          [tools setTintColor:[self.navigationController.navigationBar tintColor]];
          [tools setAlpha:[self.navigationController.navigationBar alpha]];
          NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];

          UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                  target:self action:@selector(clickSettings:)];

          UIBarButtonItem *anotherButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UITabBarSystemItemContacts
                                                                  target:self action:@selector(clickEdit:)];
          [buttons addObject:anotherButton];
          [anotherButton release];
          [buttons addObject:anotherButton1];
          [anotherButton1 release];
          [tools setItems:buttons animated:NO];
          [buttons release];
          UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools];
          self.navigationItem.rightBarButtonItem = myBtn;

          [myBtn release];
          [tools release];

          posted on 2010-11-13 22:37 seal 閱讀(577) 評論(0)  編輯  收藏 所屬分類: iPhone
          主站蜘蛛池模板: 石河子市| 海宁市| 三都| 都江堰市| 木里| 建始县| 延长县| 濮阳县| 敖汉旗| 望城县| 缙云县| 尼玛县| 樟树市| 桃源县| 会东县| 昌都县| 林周县| 华亭县| 龙胜| 乌什县| 柞水县| 葫芦岛市| 体育| 彭水| 女性| 申扎县| 威海市| 无锡市| 阿拉尔市| 福海县| 临湘市| 涡阳县| 葵青区| 永康市| 琼结县| 霍州市| 无为县| 吉安县| 丰都县| 贡觉县| 阿尔山市|