先上图:
这个是ViewController我们title是navigationbar,所以在appDelegate启动的时候使用:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
myTableViewController = [[MyTableViewController alloc] init];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:myTableViewController];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}
-(void) viewDidLoad{
[self addTilteBar];
names = [[NSArray alloc] initWithObjects:@"Paul", @"Josh", @"Al", @"Dave",@"Paul",@"Paul", @"Josh", @"Al", @"Dave",@"Paul", nil];
self.tableView =
[[UITableView alloc] initWithFrame:CGRectMake(0,0, 320.0f, 460.0f-50.0f) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
[self addBottomToolBar];
[super viewDidLoad];
}
初始化navigation bar
-(void) addTilteBar{
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.leftBarButtonItem = back;
[back release];
NSArray* array = [[NSArray alloc] initWithObjects:@"搜索周边",@"周边地图",nil];
UISegmentedControl* segment = [[UISegmentedControl alloc] initWithItems:array];
CGRect rect = CGRectMake(80.0f, 8.0f, 170.0f, 30.0f);
segment.frame = rect;
segment.segmentedControlStyle = UISegmentedControlStyleBar;
segment.selectedSegmentIndex = -1;
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
[segment release];
UIBarButtonItem *mapButton = [[UIBarButtonItem alloc]
initWithTitle:@"刷新"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(refreshButtonPressed)];
self.navigationItem.rightBarButtonItem = mapButton;
[mapButton release];
}
初始化底下的toolbar
-(void) addBottomToolBar{
UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
UIBarButtonItem *three = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
UIBarButtonItem *four = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 460-40-50, 320, 50)];
[toolbar setBarStyle:UIBarStyleBlackOpaque];
[toolbar setItems:[NSArray arrayWithObjects:flexItem, one, flexItem, two, flexItem, three, flexItem, four, flexItem, nil]];
[self.view addSubview:toolbar];
}
代码可以在 http://download.csdn.net/detail/baidu_nod/7534005下载