设置导航控制器内容
2016-07-16 07:32
218 查看
一般导航控制器内容有三个属性分别有leftBarButtonItem,rightBarButtonItem,title属性或者方法设置
注意 1,导航控制器内容只能通过栈顶控制器设置内容2,导航控制器内容位置是系统决定而大小是自己决定
具体代码如下:
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //创建一个窗口 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; //创建一个UINavigationController的根控制器 ViewController *vc = [[ViewController alloc] init]; //创建UINavigationController并将ViewController设置为UINavigationController的根控制器 UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc]; //设置窗口的根控制器 self.window.rootViewController = nc; //显示 [self.window makeKeyAndVisible]; return YES; }
ViewController.m
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor blueColor]; self.navigationItem.title = @"导航栏内容只能有栈顶控制器设置"; //使用系统定义按钮 UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil]; //设置左边按钮 self.navigationItem.leftBarButtonItem = leftItem; //创建一个UIButton设置默认和点击时的图片 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setBackgroundImage:[UIImage imageNamed:@"navigationbar_friendsearch"] forState:UIControlStateNormal]; [btn setBackgroundImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted]; //注意点:导航控制器内容的位置是系统控制的内容是自己决定 btn.frame = CGRectMake(10, 0, 35, 35); UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; //设置自定义右边按钮 self.navigationItem.rightBarButtonItem = rightItem; }
相关文章推荐
- 开源蓝牙ble-1_DA14580初级入门教程3_DA1458x软件基础教程
- 如何利用“南海事件”迅速吸粉
- hdu_1286找新朋友(欧拉定理)
- 今天鹏鹏会来,待会一起出去买东西。
- 开闭原则详解--七大面向对象设计原则(5)
- EasyUI基础知识
- PyQt5 pyuic
- EasyUI基础知识
- EasyUI基础知识
- 高斯公式,斯克托斯公式
- python之路 IO多路复用 线程进程初步了解
- 树莓派安装配置启动CHROME及FLASH支持
- 文件搜索器的实现(一)
- eclipse提交项目到github
- 安装cygwin Package: Unknown package pango1.0.sh exit code 1 解决办法
- iOS快速开发必备的几种类库总结
- Find the Celebrity
- Find the Celebrity
- Product of Array Except Self
- Longest Consecutive Sequence