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 ...
随机推荐
- Sqli-labs less 29
Less-29 首先先看下tomcat中的index.jsp文件 在apache的index.php中,sql语句为 $sql="SELECT * FROM users WHERE id=' ...
- shell脚本 -d 是目录文件,那么-e,-f分别是什么?还有"! -e"这又是什么意思呢?
-e filename 如果 filename存在,则为真-d filename 如果 filename为目录,则为真 -f filename 如果 filename为常规文件,则为真-L filen ...
- 由浅入深了解Thrift之微服务化应用架构
为什么选择微服务 一般情况下,业务应用我们都会采用模块化的分层式架构,所有的业务逻辑代码最终会在一个代码库中并统一部署,我们称这种应用架构为单体应用. 单体应用的问题是,全部开发人员会共享一个代码库, ...
- HDU 2529 Shot (物理数学题)
题目 解题过程: //物理数学题 #include<stdio.h> #include<string.h> #include<algorithm> using na ...
- iOS第三方支付-支付宝支付
处理手机中有无支付宝的情况支付宝调用接口: - (void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr ...
- Python并发与并行的新手指南
点这里 在批评Python的讨论中,常常说起Python多线程是多么的难用.还有人对 global interpreter lock(也被亲切的称为“GIL”)指指点点,说它阻碍了Python的多线程 ...
- 传说中的WCF(8):玩转消息协定
Message翻译成中文,相信各位不陌生,是啊,就是消息,在WCF中也有消息这玩意儿,不知道你怎么去理解它.反正俺的理解,就像我们互发短信一个道理,通讯的双方就是服务器与客户端,说白了吧,就是二者之间 ...
- 关于yum仓库的中的软件包下载
在Linux系统下,很多软件的安装我们都会选择使用yum的方式安装,因为简单方便,易于管理. 有时我们可能会有这样的一个需求:即喜欢上yum仓库中的一个软件了,想要下载到本地.该怎么办呢? 实现方法不 ...
- http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024
http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024 http://blog.csdn.net/kkdelta/article/detai ...
- Android核心分析之十五Android输入系统之输入路径详解
Android用户事件输入路径 1 输入路径的一般原理 按键,鼠标消息从收集到最终将发送到焦点窗口,要经历怎样的路径,是Android GWES设计方案中需要详细考虑的问题.按键,鼠标等用户消息 ...