How to Customize UITabBar on iOS 5
来源:互联网 发布:gm预测软件 编辑:程序博客网 时间:2024/06/10 07:33
How to Customize UITabBar on iOS 5
今天刚好用到UITabBar,而且是非UITabBarController的那种。发现了一篇很好的适合初学者的文章,所以转载过来自己留下!
Building the new version of the app Blocos de Rua I was challenged to customize the UITabBar
so it meets what the designer wants. In iOS 5 this is pretty easy to do but I haven’t figured out the proper way to do it from the beginning, this post is my findings on how to do it properly by correctly using the new iOS 5 APIs to customize appearance.
The final look:
Keep reading to see the code.
The appearance APIs in iOS 5 are great. They reduce lots of custom drawRect:
that used to be necessary to customize the default UIKit components. The first time I tried to customized the tab bar I had some problems with images been offset upwards because I was using the wrong methods. First thing I learned, the setFinishedSelectedImage:finishedUnselectedImage:
from UITabBarItem
is the tab’s icon not a image for the whole tab with background, icon and label.
Customize the UITabBar
is a peace of cake when you understand how the APIs should be used, take a look:
From inside out, the UITabBar
First - usually in your app delegate - set the image for the entire tab bar’s background, which represents the “normal” state of all tabs. The dimension is 320 x 49 points.
Then configure the selected state of a tab. This is necessary because in this app I don’t want the default white highlight that represents the selected tab. Pay attention to the image’s width, it must be the same of a single tab. In my case 320/4, 80 points wide.
Last but not least, the UITabBarItem
Unlike the default behavior the image shouldn’t change when the tab is selected, this is why I set the same image in both states. For each UIViewController
that will be part of the tab bar you need to configure the tab image like this:
The last detail is the title’s color on the unselected tab, they can’t be the default gray color. To change the color we need a dictionary of attributes whit the UITextAttributeTextColor
key:
That’s all folks.
转自:http://felipecypriano.com/2012/02/27/how-to-customize-uitabbar-on-ios-5/
- How to Customize UITabBar on iOS 5
- How to Customize UITabBar on iOS 5
- How to Customize UITabBar on iOS 5
- How to Customize UITabBar on iOS 5
- 自定义UITabBar=How to Customize UITabBar on iOS 5
- How to customize back button on UINavigationBar
- How to customize Larbin
- How To Customize The Tab Bar Using iOS 5 Appearance API
- How to customize ADF exception
- How to Customize Splash Logo
- How to customize xtragrid column line
- How-to: Customize Android progress bars
- How to Customize your Terminal Prompt
- iOS如何定制化Tab Bar界面(How To Customize Tab Bar Background and Appearance)
- iOS Programming 101: How To Customize Tab Bar Background and Appearance
- How to Parse HTML on iOS
- How to debug Javascript errors on iOS
- How to run cpp-tests on iOS
- LIVE555优化记录
- 判断输入年份是否合法
- UML基础与应用
- SAP MRP Made Easy -[1.1]概览[翻译]
- ECLIPSE 自测试方法
- How to Customize UITabBar on iOS 5
- css 相对定位 绝对定位 浮动 分析
- 遇见最美的时光
- 监听是否静音及音量
- SAP MRP 消耗的策略及逻辑
- 像素级的图像处理---opencv.2学习笔记1
- 非负矩阵分解:数学的奇妙力量
- Linux环境进程间通信(六): socket
- SAP MRP Made Easy - [1.3]确定需求类型