UINavigationBar功能实现
来源:互联网 发布:淘宝千人千面好用吗 编辑:程序博客网 时间:2024/05/16 03:10
IOS5中:
-(void)setBackgroundImage:(UIImage)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics
IOS6中:
在上面的方法基础上,加上[UIApplication shareApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
基础控件UINavigationController中的传值,代理传值,正向传值,反向传值
#import <UIKit/UIKit.h>//声明一个协议@protocol SendValue<NSObject>//定义一个方法- (void)sendBtnTitle:(NSString *)title;@end@interface FirstViewController : UIViewController// 定义代理@property (nonatomic, assign) id <SendValue>delegate;// 创建一个正向传值的属性@property (nonatomic,copy) NSString *currentTitle;@end//正向传值利用的是属性传值
//反向传值利用代理传值
创建一个RootViewController类和FirstViewController
分别在AppDelegate.m中调用RootViewController.h 在RootViewController.m中调用 FirstViewController.h
在RootViewController.m
{
self.view.backgroundColor = [UIColorredColor];
self.navigationItem.title =@"Root";
UIButton * btn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"push to VC2"forState:UIControlStateNormal];
[btnsetFrame:CGRectMake(30,100, 300, 50)];
[btn addTarget:selfaction:@selector(btnClicked:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btn];
}
FirstViewController.h
//协议代理实现反向传值
//声明一个协议
@protocol SendValue <NSObject>
//定义一个方法
-(void)SendTitle:(NSString *)title;
@end
@interface 下面写上
//定义代理
@property (nonatomic,assign)id <SendValue> delegate;
//创建一个正向传值的属性
@property (nonatomic,copy)NSString *currentTitle;
FirstViewController.m中
@implementation 下面写上
@synthesize delegate =_delegate;
@synthesize currentTitle =_currentTitle;
- (void)viewDidLoad
{//UINavigationController中的反向传值问题
self.view.backgroundColor = [UIColoryellowColor];
//把标题放在一个数组中 利用for循环设置
NSArray * btnTitles = [NSArrayarrayWithObjects:@"标题1",@"标题2",@"标题3",nil];
for (int i=0; i<[btnTitlescount]; i++) {
UIButton * btn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
//如果按钮的标题和属性中的_currentTitle 相同,即和根页面中的导航条的title一样
if ([_currentTitleisEqualToString:btn.currentTitle]) {
//开启选中状态
btn.selected =YES;
}
[btn setTitle:[btnTitlesobjectAtIndex:i] forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(titleBtnClicked:)forControlEvents:UIControlEventTouchUpInside];
[btnsetFrame:CGRectMake(10,80+i*40, 300, 30)];
[self.viewaddSubview:btn];
}
//对titleBtnClicked:设置
-(void)titleBtnClicked:(UIButton *)btn
{
NSString * title = btn.currentTitle;
//判断代理中是否有SendTitle:这个函数
if([_delegaterespondsToSelector:@selector(SendTitle:)]){
//代理执行自己的SendTitle 函数,传参是title
[_delegate SendTitle:title];
}
[self.navigationControllerpopViewControllerAnimated:YES];
}
在RootViewController.h中
#import <UIKit/UIKit.h>
添加头文件 #import "FirstViewController.h"
//把协议挂过来
@interface RootViewController :UIViewController <SendValue>
@end
- (void)btnClicked:(UIButton *)btn
{
FirstViewController * first = [[FirstViewControlleralloc] init];
//将当前页面的navigaItem.title传递过去
//正向传值
first.currentTitle =self.navigationItem.title;
//将代理指定为当前rootViewController类的指针
first.delegate =self;
[self.navigationControllerpushViewController:first animated:YES];
}
//实现协议定义的方法
-(void)SendTitle:(NSString *)title
{
self.navigationItem.title = title;
}
- UINavigationBar功能实现
- 全透明UINavigationBar的实现
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- uinavigationbar
- UINavigationBar 手动实现编辑和完成按钮
- iOS 实现透明UINavigationController UINavigationBar效果
- IOS 实现系统UINavigationController UINavigationBar 透明效果
- 怎么实现首页隐藏的 UINavigationBar 导航条
- 关于UIViewController添加UINavigationBar的详细实现方法
- linux网络协议栈:邻居子系统
- HelloWorld by Thrift
- Redis 分布式锁实现
- linux上SVN解决冲突的办法
- Wordpress使用"function_exists();"函数以提高主题兼容性
- UINavigationBar功能实现
- table checked row
- JSTL开发实例详解
- HTML 5 拖放
- 《牛人博客汇总》
- 视频录制压力,正反面录制视频
- CSRF(跨站请求伪造)详细说明
- SAPUI5-Button
- GRE写作必备句型