Sealyu

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

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評(píng)論 :: 0 Trackbacks
          在實(shí)際的開(kāi)發(fā)中,導(dǎo)航器是最重要的容器之一,我們經(jīng)常要在導(dǎo)航欄中添加各種樣式的按鈕,添加一個(gè)按鈕很簡(jiǎn)單,代碼如下圖: UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTi

          在實(shí)際的開(kāi)發(fā)中,導(dǎo)航器是最重要的容器之一,我們經(jīng)常要在導(dǎo)航欄中添加各種樣式的按鈕,添加一個(gè)按鈕很簡(jiǎn)單,代碼如下圖:

          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/

          在有些項(xiàng)目中要在右面添加兩個(gè)按鈕,實(shí)現(xiàn)的樣式如下圖:

           

           

          實(shí)現(xiàn)的代碼如下圖:

          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 閱讀(570) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): iPhone
          主站蜘蛛池模板: 广丰县| 公主岭市| 大足县| 和林格尔县| 义马市| 安徽省| 都匀市| 承德市| 固始县| 白水县| 廊坊市| 德安县| 合江县| 沅江市| 瑞昌市| 南汇区| 周宁县| 当雄县| 永善县| 韶山市| 肥东县| 唐海县| 临潭县| 宝兴县| 闵行区| 永嘉县| 水富县| 吴江市| 仪陇县| 阳原县| 堆龙德庆县| 赫章县| 哈尔滨市| 清镇市| 龙海市| 府谷县| 博客| 赣州市| 卢氏县| 冕宁县| 喀什市|