原文:  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. Goolg Chrome 插件开发--Hello world

    开发Chrome插件很简单,只要会web开发(html+javascript+css)那么这个就是能驾轻就熟,只需要了解一下插件具体的运行环境及要求就OK了. 1.先创建一个html文件,名字随便取, ...

  2. JavaScript 性能分析新工具 OneProfile

    OneProfile 是一个网页版的小工具,可以用全新的方式展示 JavaScript 性能分析的结果,帮助开发者洞悉函数调用关系,优化应用性能. 点击打开 OneProfile 背景 Chrome ...

  3. 控制台应用程序的Main方法

    总结一下Main方法规则: 1.Main 方法名大小写有规范. 2.Main 方法返回类型只有 void.int两种返回类型. 3.Main 方法的参数可以是string[] args,也可以为空,只 ...

  4. [Sharepoint]备份 迁移 还原

    在sharepoint 的备份当中,一般分为一个sharepoint 站点的备份和sharepoint 整个站点的备份.我们可以用sharepoint designer 进行备份, 也可以用 stsa ...

  5. Android核心分析之十五Android输入系统之输入路径详解

       Android用户事件输入路径 1 输入路径的一般原理 按键,鼠标消息从收集到最终将发送到焦点窗口,要经历怎样的路径,是Android GWES设计方案中需要详细考虑的问题.按键,鼠标等用户消息 ...

  6. VCL里为什么要用类函数代替API,为什么要用CM_消息代替虚函数

    之所以要用类函数代替API,是因为VCL对它做了一些包装,好在API起作用之前和之后做一些额外的事情:通知和判断等等.之所以类函数要包装一个CM_消息,是因为这样方便程序员(在调用类函数的基础上)截断 ...

  7. MyBatis学习总结_15_定制Mybatis自动代码生成的maven插件

    ==================================================================================================== ...

  8. Backbone seajs demo2

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. php静态

    static 是定义一个静态对象或静态变量,关于static 定义的变量或类方法有什么特性我们看完本文章的相关实例后就见分晓了. 1. 创建对象$object = new Class(),然后使用”- ...

  10. 【CCS仿真】用matlab把CCS保存的32位16进制的数据转换为十进制的数

    2013-12-04 16:37:28 使用fscanf函数即可完成. 例如,CCS保存的.dat文件Copy_of_forward_i_f.dat如下: 1651 1 81008800 0 4000 ...