控制器 ------ tabbar控制器 和 导航控制器
来源:互联网 发布:java 网络编程笔试题 编辑:程序博客网 时间:2024/05/17 04:47
1.自定义一个底部 tabbarController ,然后自定义一个tabbarbutton ,继承UITabBar, 在控制器中使用kvc模式拿到UITabBar;
1》启动控制器 tabbar
UIWindow *window = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
XBTabBarController *tab = [[XBTabBarControlleralloc]init];
window.rootViewController = tab;
self.window = window;
[self.windowmakeKeyAndVisible];
2》在tabbarController中 拿到tabbar
XBTabBar *tab = [[XBTabBaralloc]init];
//使用KVC模式设置tabbar
[selfsetValue:tab forKeyPath:@"tabBar"];
3》tabbar中定义tabbar的按钮位置,注意要在- (void)layoutSubviews中进行位置处理。
- (void)layoutSubviews{
[superlayoutSubviews];
//设置+号按钮的位置
//self.plusbtn.center = CGPointMake(self.width * 0.5, self.height * 0.5);
//设置其他tabbarbutton的位置
CGFloat tabbarbuttonW =self.frame.size.width /4;
CGFloat tabbatbuttonIndex = 0;
for ( UIView *childin self.subviews) {
Class class =NSClassFromString(@"UITabBarButton");
if ([child isKindOfClass:class]) {
// 设置宽度
CGFloat witch = tabbarbuttonW;
// 设置x
CGFloat X = tabbatbuttonIndex * tabbarbuttonW;
child.frame =CGRectMake(X, 0, witch,self.frame.size.height);
// 增加索引
tabbatbuttonIndex++;
}
}
}
4》tabbar系统会自动进行渲染,要在进行创建的时候进行禁止渲染
// 设置vcTabBarItem
- (void)setUpController:(UIViewController*)vcClack title:(NSString*)title imageName:(NSString*)imageName SelecdImage:(NSString*)SelecdImage{
vcClack.title = title;
vcClack.tabBarItem.image = [UIImageimageNamed:imageName];
UIImage * meImage = [UIImageimageNamed:SelecdImage];
vcClack.tabBarItem.selectedImage = [meImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
XBNavigationController *nav = [[XBNavigationControlleralloc]initWithRootViewController:vcClack];
[selfaddChildViewController:nav];
}
- 控制器 ------ tabbar控制器 和 导航控制器
- 导航控制器及TabBar控制器
- 控制器和导航控制器
- 导航控制器和标签控制器
- 导航控制器和tabBar控制器title的设置(UITabBarItem 和 UINavigationBarItem 的title)
- 建立导航控制器和Tab Bar控制器
- 导航控制器和分栏控制器小结1
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 控制器
- 控制器
- Yii2使用Redis - 从安装redis到使用
- 安卓开发学习之010 TableLayout详解+计算器实现
- 一道易错的题
- 导航
- jgroups 例子
- 控制器 ------ tabbar控制器 和 导航控制器
- Eclipse项目导入到Android studio中
- Android 获取手机联系人代码
- jgroups API
- Rotate Image
- UNITY 文件路径整理(偷的)
- markdown怎么玩~
- 快速傅里叶变换FFT(一维)
- Hadoop、Spark、HBase与Redis的适用性见解