自定义UITabBarController及tabBarItem的具体设置
2016-05-13 00:00
459 查看
摘要: 自定义UITabBarController tabBarItem设置
//以下是初始化子控制器抽离出来的方法
- (void)addChildViewControllerWithTitle:(NSString *)title imageName:(NSString *)imageName ctrl:(UIViewController *)ctrl {
ctrl.tabBarItem.title = title;
//1.解决文字变蓝的问题
//初始化文字的属性
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
//设置tabbarItem 标题的文字属性
[ctrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
ctrl.tabBarItem.image = [UIImage imageNamed:imageName];
//2.解决图片变蓝的问题
UIImage *originalImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]];
ctrl.tabBarItem.selectedImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//3.如果图片上面包括了icon与文字,要把图片往下移动的话。可以使用下面这句代码
ctrl.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
[self addChildViewController:ctrl];
}
//以下是初始化子控制器抽离出来的方法
- (void)addChildViewControllerWithTitle:(NSString *)title imageName:(NSString *)imageName ctrl:(UIViewController *)ctrl {
ctrl.tabBarItem.title = title;
//1.解决文字变蓝的问题
//初始化文字的属性
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
//设置tabbarItem 标题的文字属性
[ctrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
ctrl.tabBarItem.image = [UIImage imageNamed:imageName];
//2.解决图片变蓝的问题
UIImage *originalImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]];
ctrl.tabBarItem.selectedImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//3.如果图片上面包括了icon与文字,要把图片往下移动的话。可以使用下面这句代码
ctrl.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
[self addChildViewController:ctrl];
}
相关文章推荐
- 华为Quidway交换机DHCP IP地址排除
- SPOJ GSS5 Can you answer these queries V
- SPOJ GSS3 Can you answer these queries III
- SPOJ GSS1 Can you answer these queries I
- Codeforces 350 Div2 E Correct Bracket Sequence Editor(list模拟)
- iOS获取设备唯一的UUID(解决删除应用UUID变更的问题)
- UIImageView和UIImage
- HDU3397 Sequence operation(线段树的区间合并)
- SDWebImage与UIScrollView或UICollectionView一起使用多次收到“Received memory warning.”,最终程序闪退的原因分析和解决办法。
- forward(request,reponse)与sendRedirect
- 可修改UID的白卡,请问为什么一般读写器不能修改这种卡的UID,必须要特定的读写器才能修改?
- iOS开发封装带有Button的UIView控件,使用target-action模式给button添加点击事件
- 129.Longest Consecutive Sequence
- iOS开发封装带有Button的UIView控件,使用代理给button添加点击事件
- deep learning---利用caffe在vgg-face上finetuing自己的人脸数据
- mui图片预览
- weblogic 下异常 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken
- 62. Unique Paths
- leetcode_347 Top K Frequent Elements
- Guid的使用