定制UITabBar显示样式

定制UITabBar显示样式

 

思路是这样子的:

1. 初始化UITabBarController,并装载进来几个其他的ViewController

2. 获取每个控制器的UITabBarItem

3. 单独配置每个ViewController对应的UITabBarItem(其中,文字可以设置偏移量)

就这么简单哦!

 

 

 

问:如何设置UITabBarController高亮选中的颜色值呢?

 

问:[UITabBar appearance]能干什么?

他是进行UITabBarController全局设定的,也就是说不需要你一个一个的单独设定.

http://www.altinkonline.nl/tutorials/xcode/uitabbar/customizing-background-tintcolor-and-selected-image/

To customize the UITabBar you must have an referrer to the UITabBarController.

Open your class wich refers to the UITabBarController. Add the code below in your class. E.g. in the viewDidLoad: method.

Customize the UITabBar by setting the backgroundimage of your UITabBar.

    UIImage *tabBackground = [[UIImage imageNamed:@"tabBarBackground.jpg"] 
                              resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    // Set background for all UITabBars
    [[UITabBar appearance] setBackgroundImage:tabBackground];
    // Set background for only this UITabBar
    [[tabBarController tabBar] setBackgroundImage:tabBackground];

Customize the UITabBar by setting the tintColor for the images.

    // Set tint color for the images only for this tabbar
    [[tabBarController tabBar] setSelectedImageTintColor:[UIColor brownColor]];
    [[tabBarController tabBar] setTintColor:[UIColor whiteColor]];
    // Set tint color for the images for all tabbars
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor brownColor]];
    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];

Customize the UITabBar by setting the selectionIndicatorImage.

    // Set selectionIndicatorImage for this tabbar
    [[tabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab.png"]];
    // Set selectionIndicatorImage for all tabbars
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab.png"]];

Now you've an full customized UITabBar!

 

问:UITabBar的图片尺寸是多少呢?

icon为 60x60pix 的png图片,使用时请用如下格式(如图片名字为 newDay@2x, 使用时直接使用名字即可)

 

问:如何隐藏UITabBar上的那条黑线?

[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tm.png"]];

The shadow image to be used for the tab bar.
The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set using the backgroundImage property. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

根据这个描述信息来看,如果设定了setShadowImage,那也必须设定背景图片哦.

 

附录:

1. 样式

 

2. 一些尺寸

 

 

转载于:https://www.cnblogs.com/YouXianMing/p/3727320.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值