在画面跳转中,UIKit库提供的UITabBarController和UINavigationController两大类是最为常用的类。
今天,趁着假期有空,总结一下UITabViewController的运用
1.UITabBar的items属性中以NSArray形式保存管理的标签条项目;
2.当前选中的标签的索引保存在UITabBar的selectedItem属性中;
3.UITabBarController管理下的个UIViewController的tabBarItem属性会自动追加到UITabBar的items属性中;
4.设置系统标签项目可以用: - (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;
self.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
self.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
当然,UITabBarSystemItem的样式还有很多,感兴趣的猿们可以自己去一一定制,看看效果。
5.需要自己定制标签样式,运用- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag;方法
self.title = @"Hello";
UIImage* icon = [UIImage imageNamed:@"ball1.png"];
self.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"Hello" image:icon tag:0] ;
6.如果需要添加6个及其以上的Item,标签条上又只能最多显示5个图标,此时最后以后会自动编程UITabBarSystemItemMore图标;
7.添加标签条上的标记:直接设置UITabBarItem的badgeValue属性来设置:
self.tabBarItem.badgeValue = @"2";
上面的总结,应该就是UITabBarController一些基本要点了,给大家一个demo吧,网上找的,我进行了一些基本的修改,但是为了正确显示,有些
效果注销了,大家如果要看截图的效果,可以自己取消注释,来实现。