`
iaiai
  • 浏览: 2144705 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[IOS]关于在UIViewController页面添加UINavigationBar的方法

 
阅读更多


//解决问题的关键就下面的这段代码

UIView *headerView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 44)];
self.tableView.tableHeaderView = headerView;
[headerView release];
//加了上面的代码之后tabview就向下移了44个像素,那刚好放上navbar
CGRect aScreenRect = [[UIScreen mainScreen] bounds];

//创建navbar
UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, aScreenRect.size.width, 44)];
//创建navbaritem
UINavigationItem *NavTitle = [[UINavigationItem alloc] initWithTitle:@"详细介绍"];

[nav pushNavigationItem:NavTitle animated:YES];

[self.view addSubview:nav];

//创建barbutton 创建系统样式的
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(navBackBt:)];

//设置barbutton
NavTitle.leftBarButtonItem = item;
[nav setItems:[NSArray arrayWithObject:NavTitle]];

[item release];
[NavTitle release];
[nav release];

这样就OK了
  • 大小: 28.7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics