自定义TabBar的尝试(1)
来源:互联网 发布:vmware12安装linux系统 编辑:程序博客网 时间:2024/06/05 15:38
看到了其他人做过的自定义TabBar,然后想自己也去搞搞看
先来个初步的效果图
TabBar中主要是用几个UIButton贴在View上实现的
首先设置下背景View
self.backgroundColor = [UIColorcolorWithRed:248.0f/255.0fgreen:248.0f/255.0fblue:248.0f/255.0falpha:1];
self.layer.shadowColor = [[UIColorgrayColor]CGColor];
self.layer.shadowOffset =CGSizeMake(-1, -1);
self.layer.shadowOpacity =0.3f;
self.layer.shadowRadius =4;
self.alpha =0.8f;
for循环创建TabBarItem,可以自定义title和数量
selectImgArr = [[NSMutableArrayalloc]init];
unSelectImgArr = [[NSMutableArrayalloc]init];
for (int i =0; i < itemCount; i++) {
[selectImgArraddObject:[[UIImagealloc]init]];
[unSelectImgArraddObject:[[UIImagealloc]init]];
UIButton* itemBtn;
if (i ==2) {
itemBtn = [UIButtonbuttonWithType:UIButtonTypeContactAdd];
itemBtn.selected =YES;
}else
{
itemBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
[itemBtn setTitle:[titleArrayobjectAtIndex:i]forState:UIControlStateNormal];
}
[itemBtn.titleLabelsetFont:[CrewCommonDealgetFont:11]];
[itemBtn setTitleColor:[UIColorgrayColor]forState:UIControlStateNormal];
[itemBtn setTitleColor:[UIColorredColor]forState:UIControlStateHighlighted];
itemBtn.tag =1000+i;
itemBtn.frame =CGRectMake(i*kMainScreen_Width/ItemCount,0,kMainScreen_Width/ItemCount,ItemH);
[itemBtn addTarget:selfaction:@selector(selectItem:)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:itemBtn];
}
控制没个Button的位置
itemBtn.frame =CGRectMake(i*kMainScreen_Width/ItemCount,0,kMainScreen_Width/ItemCount,ItemH);
对UIButton图片进行设置并使用UIEdgeInsets调整图片与title对应位置
之后建立delegate,设定选中状态,在VC中通过Action调用原生tabbarVC实现不同VC的跳转
self.selectedIndex = itemTag;
- 自定义TabBar的尝试(1)
- iOS自定义tabbar(没有tabbar上的黑线)
- Android自定义的TabBar
- 隐藏自定义的tabBar
- 自定义tabbar的步骤
- 添加自定义的tabBar
- Tabbar的自定义
- 自定义tabBar的使用
- 自定义Tabbar的badgeView
- 自定义UITabBarController的tabBar背景图片
- 自定义UITabBarController的tabBar背景图片
- 自定义UITabBarController的tabBar背景图片
- 自定义tabBar的一个方法
- 关于自定义tabbar的实现
- iOS 自定义tabbar的发现
- iOS自定义 TabBar的技巧
- TabBar自定义图片的设置
- 自定义TabBar中间的Item
- 中国天气网 天气预报API 国家气象局 根据城市名称抓取城市ID,XML格式、JSON格式、图片代码
- 过滤器、监听器、拦截器的区别
- java实现DES数据加密与解密
- SCI写作不得不说的经典替换词
- Cannot find or open the PDB file
- 自定义TabBar的尝试(1)
- 移动web:翻页场景动画(结婚浪漫请柬)
- UML类图简介
- 更新node后,pomelo异常 not a package /usr/local/bin/pomelo
- debug的快捷键
- 移动端web开发 chapter 1 – introduction
- Android使用DrawerLayout创建左右两个抽屉菜单
- Android ClassLoader机制
- java过滤器和监听器详解