iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结
原文: 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自定义方法总结的更多相关文章
- 【转】 学习ios(必看经典)牛人40天精通iOS开发的学习方法【2015.12.2
原文网址:http://bbs.51cto.com/thread-1099956-1.html 亲爱的学员们: 如今,各路开发者为淘一桶金也纷纷转入iOS开发的行列.你心动了吗?想要行动吗?知道如何做 ...
- IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例
IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...
- iOS开发系列--视图切换
概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...
- iOS开发UINavigation——导航控制器UINavigationController
iOS开发UINavigation系列一——导航栏UINavigtionBar摘要iOS中的导航条可以附着于导航控制器之中使用,也可以在controller中单独使用,这篇博客,主要讨论有关导航栏的使 ...
- iOS开发200个tips总结(一)
tip 1 : 给UIImage添加毛玻璃效果 func blurImage(value:NSNumber) -> UIImage { let context = CIContext(opti ...
- iOS开发常用的第三方类库
在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使我们的开发变得更有效率:同时,也可以从它们的源代码中学习到很多有用的东西. Reachability 检测网络连接 用来检查网 ...
- 【转】iOS开发常用的第三方类库
原文: http://blog.csdn.net/xiazailushang/article/details/9716043 在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使 ...
- 【转】iOS 开发怎么入门?
原文网址:http://www.zhihu.com/question/20264108 iOS 开发怎么入门? 请问有设计模式.内存管理方面的资料吗?最好有除了官方文档之外的其它内容,10 条评论 分 ...
- iOS开发tips总结
tip 1 : 给UIImage添加毛玻璃效果 func blurImage(value:NSNumber) -> UIImage { let context = CIContext(opti ...
随机推荐
- hdu5017 Ellipsoid(旋转)
比赛的时候跳进这个大坑里,最后代码是写出来了.看到好像很多都是模拟退火做的,下面提供一个奇怪的思路吧. ax^2+by^2+cz^2+dyz+exz+fxy=1(*) 通过一些奇特的YY我们可以知道这 ...
- JavaScript call和apply的用法
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- java 静态构造函数
在java中貌似是没有静态构造函数的. 不过用下面的方式同样可以实现效果. static { }//end 这是静态代码块
- IIS 发布程序的一些心得
1.应用程序池一般自己建立对应Framework版本的程序池,并托管管道模式为经典 2.在IIS根目录双击,右侧的“ISAPI和CGI限制” 双击打开,将自己所需要的Framework版本的限制设置为 ...
- hdu 3590 PP and QQ 博弈论
思路: 在贾志豪神牛的论文 里,这两种游戏都有 其中树的删边游戏:叶子节点的SG值为0:中间节点的SG值为它的所有子节点的SG值加1 后的异或和. ANTI-SG:先手必胜当且仅当:(1)游戏的SG函 ...
- 如何理解 MySQL 中的 <=> 操作符?
问题 : 我在看以前的一个开发者的代码时看到 WHERE p.name <=> NULL 在这个查询语句中 <=>符号是什么意思啊?是不是和 =号是一样啊?还是一个语法错误啊? ...
- sublime3配置Quick-X+自动错误提示
sublime3配置 安装Package Control 配置Quick-x API提示 配置Lua自动语法错误提示 sublime3 安装 Package Control View->Show ...
- C# winform窗体假死
C# winform窗体假死 我们经常会遇到当执行一个比较大的函数时,窗体会出现假死的现象,给用户的体验不是很好,于是我们遇到了问题,那么就必须解决,我们该如何解决呢,首先在自己的脑里画个问号,接下 ...
- Data Base Oracle下载及安装
Oracle 下载及安装 一.官方下地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/in ...
- Android应用开发学习笔记之菜单
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android中的菜单分为选项菜单(OptionMenu)和上下文菜单(Context Menu).通常使用菜单资源 ...