IOS toolbar,NavigationItem,UISegmentedControl,tableview和titile写法

先上图:



这个是ViewController我们title是navigationbar,所以在appDelegate启动的时候使用:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    myTableViewController = [[MyTableViewController alloc] init];
    
    UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:myTableViewController];
    
    [window addSubview:nav.view];
    [window makeKeyAndVisible];
}



这个UIViewController有一个属性tableview,先初始化tableView
-(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下载


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值