UI学习

来源:互联网 发布:网络品牌营销策略 编辑:程序博客网 时间:2024/05/16 01:10
day7 UITabBarController


UITabBarController
标签控制器
系统tabBarItem

1. UITabBarController
UITabBarItem
代理方法
NSUserDefaults
System item:
UITabBarItem alloc initWithTabBarSystemItem:tag:
We can’t set the title and image if use the systemItem
用系统预置好item无法设置标题和图片

Noted the loadView viewDidLoad and willWillAppear executed only for current controller
.moreNavigationController not in viewControllers
selectedIndex
selectedViewController
delegate方法的使用
NSUserDefault的使用
// 注:住偏好设置里面存的值比较有限,只支持以下几种:
// Array Dictionary BOOL Data Date Number String简单的类型
// [userDefault setBool:(BOOL) forKey:(NSString *)];
// [userDefault boolForKey:(NSString *)]
// [userDefault setInteger:(NSInteger) forKey:(NSString *)];
// [userDefault integerForKey:(NSString *)]
// 往偏好设置中存储Data不推荐用
// 偏好设置使用场景是一些简单的用户操作,设置等,不宜存储大容量和复杂的数据
// 注:往偏好里面基于同一个key赋值会把原来相同key对应的值覆盖掉
——————————————————————————————
2. 定制TabBarController & item  
项目爱限免界面搭建




NSArray *commonImgNames = @[@"tabbar_limitfree", @"tabbar_reduceprice", @"tabbar_appfree", @"tabbar_subject", @"tabbar_rank"];
NSArray *titles = @[@"限免", @"降价", @"免费", @"专题", @"热榜"];

设置
vc.tabBarItem.image
// vc.title = @“1512棒棒哒”;
vc.tabBarItem.title = …
也可以这样:
[[UITabBarItem alloc] initWithTitle:image:tag:]

注意:the vc.title 相当于下面这两句
vc.navigationItem.title = …
vc.tabBarItem.title = …

// 设置微章
vc.tabBarItem.badgeValue = @"4";

[item setFinishedSelectedImage:withFinishedUnselectedImage:]; is deprecated.

TabBar:
tintColor
barTintColor
backgroundImage

通过UIAppearance设置item的标题颜色
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];

定制item,设置普通图片、选中图片和标题
第一种方式:
vc.tabBarItem.image = …
vc.tabBarItem.selectedImage = … noted the renderingMode of image
vc.tabBarItem.title

上面三句代码对应:
[[UITabBarItem alloc] initWithTitle:image:selectedImage:]

设置选中标题颜色:
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName :[UIColor orangeColor]} forState:UIControlStateSelected];

限免
tabbar_limitfree.png
tabbar_limitfree_press.png

降价
tabbar_reduceprice.png
tabbar_reduceprice_press.png

免费
tabbar_appfree
tabbar_appfree_press

专题
tabbar_subject
tabbar_subject_press

热榜
tabbar_rank
tabbar_rank_press
——————————————————————————————
3. 自定制tabBar

思路:
1. 把系统的tabBar隐藏掉
2. 新建imageView,在上面加一个个button 并给button设置图片
3. 当点击其中一个button时触发相应的方法并跳转到对应的控制器.selectedViewController = …



—————————————————————————————
定制TabBarController 2

code4.app

tab_feed.png tab_live      tab_feed_profile.png tab_messages.png
给ViewController做扩展
+ (instancetype) viewControllerWithTabTitle:(NSString*)title image:(UIImage*)image selectedImage:(UIImage *)selectedImage

实现中间大按钮的思路:加一个按钮,把这个按钮放在中间位置
CGFloat heightDifference = image.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
    button.center = self.tabBar.center;
else
{
    CGPoint center = self.tabBar.center;
    center.y = center.y - heightDifference/2.0;
    button.center = center;
}
—————————————————————————————

作业:






0 0