一、添加系统自带的控件
①按钮效果有三种style可选
UIBarButtonItemStyleBordered
UIBarButtonItemStyleDone
UIBarButtonItemStylePlain
UIBarButtonItem *borderedBar = [[UIBarButtonItem alloc] initWithTitle:@"borderedBar" style:UIBarButtonItemStyleBordered target:self action:@selector(action)];
self.navigationItem.rightBarButtonItem = borderedBar;
添加方法如上,效果分别如下三个图:
②带图片效果Identifier有以下类型
UIBarButtonSystemItemDone,
UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItemBookmarks,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItemUndo,
UIBarButtonSystemItemRedo,
UIBarButtonSystemItemPageCurl//只能在ToolBar上显示
添加方法:其他类型只需将对应的Item换掉即可
UIBarButtonItem *Done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done)];
self.navigationItem.rightBarButtonItem = Done;
效果:
UIBarButtonSystemItemDone
UIBarButtonSystemItemCancel
UIBarButtonSystemItemEdit
UIBarButtonSystemItemSave:
UIBarButtonSystemItemAdd:
UIBarButtonSystemItemFlexibleSpace和
UIBarButtonSystemItemFixedSpace这两种类型是不能单独用在一个Item上的,这个是在以按钮数组添加到toolBar上时用来排列位置时使用的,本文不做说明,下次再详细讲述
UIBarButtonSystemItemCompose
UIBarButtonSystemItemReply
UIBarButtonSystemItemAction
UIBarButtonSystemItemOrganize
UIBarButtonSystemItemBookmarks
UIBarButtonSystemItemSearch
UIBarButtonSystemItemRefresh
UIBarButtonSystemItemStop
UIBarButtonSystemItemCamera
UIBarButtonSystemItemTrash
UIBarButtonSystemItemPlay
UIBarButtonSystemItemPause
UIBarButtonSystemItemRewind
UIBarButtonSystemItemFastForward
UIBarButtonSystemItemUndo
UIBarButtonSystemItemRedo
UIBarButtonSystemItemPageCurl
二、在navigationItem上添加segment,Swich等控件,效果如下图
UISegmentedControl *mySegment;
mySegment = [[UISegmentedControl alloc] initWithFrame:CGRectMake(218.0f, 8.0, 100.0f, 30.0f)];
[mySegment insertSegmentWithTitle:@"分配" atIndex:0 animated:YES];
[mySegment insertSegmentWithTitle:@"处理" atIndex:1 animated:YES];
mySegment.segmentedControlStyle = UISegmentedControlStyleBar;
mySegment.selectedSegmentIndex = 0;
[self.navigationController.navigationBar addSubview:mySegment];
添加switch等控件也是如此方法