原文:  http://blog.csdn.net/songrotek/article/details/8692866?utm_source=tuicool

对于UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem这几种控件的自定义,因为具备共同性,因此放在一起讨论。

通常有两种方式来实现自定义。

1)获取控件的对象,然后对这个特定的对象进行特定的修改。

2)利用UIAppearance来实现对所有同类控件及特定同类的自定义。因为大多数应用里面的自定义为了美观,基本上相同类的控件自定义方式都一样,因此采用UIAppearance来使得界面的自定义变得非常方便。对于这种方式,通常在AppDelegate.m文件中实现,在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 这个方法内实现。

这里介绍一下UIAppearance的使用,参考自“UIAppearance protocol reference",有两种方式:

1、自定义所有类对象的显示。

[[UINavigationBar appearance] setTintColor:myColor];

2、自定义包含在特定containerclass 的类对象的显示。这主要针对UIBarButtonItem,就是说有的UIBarButtonItem在UINavigationBar中,有的在UIToolbar中,我们可以选择性的对存在于哪个bar中的button进行自定义。举例如下:

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]setTintColor:myNavBarColor];

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class],[UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setTintColor:myToolbarColor];

下面总结一下各控件使用UIAppearance自定义的Methods。摘自各苹果官方的Reference.注意下面的方法同样可以单独用于某个单独的对象。

1、UIToolbar

Customizing Appearance

– backgroundImageForToolbarPosition:barMetrics:(page 7)
Returns the image to use for the background in a given position and with given metrics.

– setBackgroundImage:forToolbarPosition:barMetrics:(page 7)
Sets the image to use for the background in a given position and with given metrics.

– shadowImageForToolbarPosition:(page 9)
Returns the image to use for the toolbar shadow in a given position.

– setShadowImage:forToolbarPosition:(page 9)
Sets the image to use for the toolbar shadow in a given position.

tintColor(page 6) property
The color used to tint the bar.

2、UITabBar

Customizing Appearance

backgroundImage (page 5)propertyThe background image for the bar.

selectedImageTintColor (page 7) property
The tint color to apply to the gradient image used when creating the selected image.

selectionIndicatorImage (page 8) propertyThe image used for the selection indicator.

shadowImage (page 8)property
The shadow image to be used for the tab bar.

tintColor (page 8)property
The tint color to apply to the tab bar background.

3、UINavigationBar

Customizing the Bar Appearance

tintColor (page 9)property
The color used to tint the bar.

–backgroundImageForBarMetrics:(page11)
Returns the background image for given bar metrics.

–  setBackgroundImage:forBarMetrics:(page 13)Sets the background image for given bar metrics.

–  titleVerticalPositionAdjustmentForBarMetrics:(page 14)Returns the title’s vertical position adjustment for given bar metrics.

–  setTitleVerticalPositionAdjustment:forBarMetrics:(page 14)Sets the title’s vertical position adjustment for given bar metrics.

titleTextAttributes (page 9) propertyDisplay attributes for the bar’s title text.

4、UIBarButtonItem

Customizing Appearance

tintColor(page 9) property
The tint color for the button item.

–  backButtonBackgroundImageForState:barMetrics:(page 10)

Returns the back button background image for a given control state and bar metrics.

–  setBackButtonBackgroundImage:forState:barMetrics:(page 17)

Sets the back button background image for a given control state and bar metrics

–backButtonTitlePositionAdjustmentForBarMetrics:(page11)Returns the back button title offset for given bar metrics.

– setBackButtonTitlePositionAdjustment:forBarMetrics:(page 19)Sets the back button title offset for given bar metrics

– backButtonBackgroundVerticalPositionAdjustmentForBarMetrics:(page 10)Returns the back button vertical position offset for given bar metrics.

– setBackButtonBackgroundVerticalPositionAdjustment:forBarMetrics:(page 18)Sets the back button vertical position offset for given bar metrics.

– backgroundVerticalPositionAdjustmentForBarMetrics:(page 13)Returns the background vertical position offset for given bar metrics.

– setBackgroundVerticalPositionAdjustment:forBarMetrics:(page 21)Sets the background vertical position offset for given bar metrics.

–backgroundImageForState:barMetrics:(page11)

Returns the background image for a given state and bar metrics.

– setBackgroundImage:forState:barMetrics:(page 19)

Sets the background image for a given state and bar metrics.

– backgroundImageForState:style:barMetrics:(page 12)

Returns the background image for the specified state, style, and metrics.

– setBackgroundImage:forState:style:barMetrics:(page 20)

Sets the background image for the specified state, style, and metrics.

– titlePositionAdjustmentForBarMetrics:(page 22)Returns the title offset for given bar metrics.

– setTitlePositionAdjustment:forBarMetrics:(page 21)Sets the title offset for given bar metrics.

5、UITabBarItem

Customizing Appearance

– titlePositionAdjustment(page 8)
Returns the offset to use to adjust the title position.

– setTitlePositionAdjustment:(page 8)
Sets the offset to use to adjust the title position.

除此之外,就是针对特定对象进行的自定义了。

1、UITabBarItem

– finishedSelectedImage (page 5)Returns the finished selected image.

– finishedUnselectedImage(page 5)Returns the finished unselected image.

– setFinishedSelectedImage:withFinishedUnselectedImage:(page 7)Sets the finished selected and unselected images.

上面的方法用于更改每个单独的TabBarItem 选中及未选中的图像

2、UIBarButtonItem

style (page 8)propertyThe style of the item.

possibleTitles (page 7)property
The set of possible titles to display on the bar button.

width (page 9)propertyThe width of the item.

customView (page 7)property
A custom view representing the item.

3、UINavigationBar

barStyle (page 7)property
The appearance of the navigation bar.

shadowImage (page 8)property
The shadow image to be used for the navigation bar.

translucent (page 10)property
A Boolean value indicating whether the navigation bar is only partially opaque.

基本上,把这些方法搞定,自定义就易如反掌了。

iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结的更多相关文章

  1. 【转】 学习ios(必看经典)牛人40天精通iOS开发的学习方法【2015.12.2

    原文网址:http://bbs.51cto.com/thread-1099956-1.html 亲爱的学员们: 如今,各路开发者为淘一桶金也纷纷转入iOS开发的行列.你心动了吗?想要行动吗?知道如何做 ...

  2. IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例

    IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...

  3. iOS开发系列--视图切换

    概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...

  4. iOS开发UINavigation——导航控制器UINavigationController

    iOS开发UINavigation系列一——导航栏UINavigtionBar摘要iOS中的导航条可以附着于导航控制器之中使用,也可以在controller中单独使用,这篇博客,主要讨论有关导航栏的使 ...

  5. iOS开发200个tips总结(一)

    tip 1 :  给UIImage添加毛玻璃效果 func blurImage(value:NSNumber) -> UIImage { let context = CIContext(opti ...

  6. iOS开发常用的第三方类库

    在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使我们的开发变得更有效率:同时,也可以从它们的源代码中学习到很多有用的东西. Reachability 检测网络连接 用来检查网 ...

  7. 【转】iOS开发常用的第三方类库

    原文: http://blog.csdn.net/xiazailushang/article/details/9716043 在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使 ...

  8. 【转】iOS 开发怎么入门?

    原文网址:http://www.zhihu.com/question/20264108 iOS 开发怎么入门? 请问有设计模式.内存管理方面的资料吗?最好有除了官方文档之外的其它内容,10 条评论 分 ...

  9. iOS开发tips总结

    tip 1 :  给UIImage添加毛玻璃效果 func blurImage(value:NSNumber) -> UIImage { let context = CIContext(opti ...

随机推荐

  1. Sqli-labs less 55

    Less-55 本关的sql语句为: $sql="SELECT * FROM security.users WHERE id=($id) LIMIT 0,1"; 其余和less54 ...

  2. POJ 3255

    Roadblocks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6605   Accepted: 2458 Descri ...

  3. C# 中Newtonsoft.Json的安装和使用

    官网参考:http://json.codeplex.com/ 在程序包管理控制台,键入NuGet命令  install-package Newtonsoft.Json  安装Newtonsoft.Js ...

  4. 从xml文件中读取注释

    void Main() {     string dirp=@"E:\Cread\UP4201308.bak\UP4.BAK\ExportPath\ConfigFile\";   ...

  5. POJ 3468 A Simple Problem with Integers(线段树)

    题目链接 题意 : 给你n个数,进行两种操作,第一种是将a到b上所有元素都加上c,第二种是查询a到b上所有元素之和输出. 思路 : 线段树,以前写过博客,但是现在在重刷,风格改变,,所以重新写一篇.. ...

  6. BackgroundWorker组件

    BackgroundWorker组件封装了后台线程的操作,并且直接利用线程池,无需自己管理线程池等复杂问题. 它主要适用于 比如界面后台加载数据,进度显示,上传下载文件,日月结等 这些都是繁重的劳动, ...

  7. DP+矩阵快速幂 HDOJ 5318 The Goddess Of The Moon

    题目传送门 /* DP::dp[i][k] 表示选择i个字符串,最后一次是k类型的字符串,它由sum (dp[i-1][j]) (a[j], a[k] is ok)累加而来 矩阵快速幂:将n个字符串看 ...

  8. 使用内网的Docker Image启动AcmeAir应用

    1.修改docker启动选项,添加信赖私有仓库 为了拉取docker.oneapm.me仓库里的镜像,我们需要将它添加为信赖仓库,方式是在启动选项中添加 --insecure-registry doc ...

  9. Mysql笔记——触发器简单实例

    首先贴上触发器语法吧: CREATE TRIGGER <触发器名称> –触发器必须有名字,最多64个字符,可能后面会附有分隔符.它和MySQL中其他对象的命名方式基本相象. { BEFOR ...

  10. springMVC找不到JS等文件

     应用springMVC时 JS等文件找不到错误 应用springMVC时如果配置URL映射时如下配置 <servlet>        <servlet-name>appSe ...