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 閱讀(571) 評論(0)  編輯  收藏 所屬分類: iPhone
          主站蜘蛛池模板: 沙坪坝区| 青河县| 桦川县| 萝北县| 清涧县| 武冈市| 铁岭县| 盐源县| 游戏| 台山市| 二手房| 关岭| 勃利县| 蒙城县| 襄垣县| 长子县| 西畴县| 澄迈县| 香格里拉县| 乌拉特后旗| 合作市| 乌恰县| 哈密市| 平塘县| 双峰县| 济南市| 西宁市| 孝感市| 军事| 赫章县| 阳曲县| 鹿邑县| 巴林左旗| 合作市| 葫芦岛市| 竹溪县| 东莞市| 榆中县| 五峰| 双辽市| 衡水市|