自定义UINavigationItem的两种方法以及相应的隐藏方法
2015-12-14 17:32
399 查看
http://www.cnblogs.com/wengzilin/p/3534315.html
第一种:
UIImage *searchimage=[UIImage imageNamed:@"search.png"];
UIBarButtonItem *barbtn=[[[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStyleDone target:self action:@selector(searchprogram)] autoRelease];
barbtn.image=searchimage;
self.navigationItem.rightBarButtonItem=barbtn;
这种设置出来的item图片跟大小是固定的
其隐藏方法是:在需要隐藏的时候self.navigationItem.xxxItem = nil;
显示方法是重新alloc-init一次;
第二种:
IButton*rightButton = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,30,30)];
[rightButtonsetImage:[UIImageimageNamed:@"search.png"]forState:UIControlStateNormal];
[rightButtonaddTarget:selfaction:@selector(searchprogram)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem*rightItem = [[UIBarButtonItemalloc]initWithCustomView:rightButton];
[rightButton release];
self.navigationItem.rightBarButtonItem= rightItem;
[rightItem release];
这种方式设计出来的item比较灵活,尤其是在 隐藏显示的时候:
隐藏方法:self.navigationItem.xxxItem.customView.hidden =YES;
显示方法,同上xxx.hidden = NO;
这种方式更合理一些,因为不需要不断的创建/消除,所以推荐用这种方法!
第三种:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(methodtocall:) ];
第一种:
UIImage *searchimage=[UIImage imageNamed:@"search.png"];
UIBarButtonItem *barbtn=[[[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStyleDone target:self action:@selector(searchprogram)] autoRelease];
barbtn.image=searchimage;
self.navigationItem.rightBarButtonItem=barbtn;
这种设置出来的item图片跟大小是固定的
其隐藏方法是:在需要隐藏的时候self.navigationItem.xxxItem = nil;
显示方法是重新alloc-init一次;
第二种:
IButton*rightButton = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,30,30)];
[rightButtonsetImage:[UIImageimageNamed:@"search.png"]forState:UIControlStateNormal];
[rightButtonaddTarget:selfaction:@selector(searchprogram)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem*rightItem = [[UIBarButtonItemalloc]initWithCustomView:rightButton];
[rightButton release];
self.navigationItem.rightBarButtonItem= rightItem;
[rightItem release];
这种方式设计出来的item比较灵活,尤其是在 隐藏显示的时候:
隐藏方法:self.navigationItem.xxxItem.customView.hidden =YES;
显示方法,同上xxx.hidden = NO;
这种方式更合理一些,因为不需要不断的创建/消除,所以推荐用这种方法!
第三种:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(methodtocall:) ];
相关文章推荐
- Sqoop Developer’s Guide v1.4.6 (Sqoop开发者指南,中文版)
- iOS-UILabel的宽度自适应文字
- ZnDuiDesigner 版本更新
- 蓝牙BR/EDR和Bluetooth Smart的十大重要区别
- Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
- UICollectionView的简单使用(一)
- Leetcode194: Range Sum Query 2D - Immutable
- openstack devstack tox ValueError: need more than 1 value to unpack
- iOS开发备忘录:自定义UINavigationBar背景图片和Back按钮
- uilabel的字体不一致
- LeetCode 300 Longest Increasing Subsequence
- django queryset values&values_list
- easyui dialog 引入jsp页面赋值
- Leetcode193: Range Sum Query - Immutable
- Android Stuido 导出 APK
- [ERROR] The goal you specified requires a project to execute but there is no POM in this directory
- Storm 提交拓扑后UI中spout、bolt的Num都显示为0
- rpmbuild线上实战
- 为嵌套在左右滑动的UIScrollview上的UITableView增加滑动删除
- iOS 十六进制的颜色值转换为UIColor