设置控件全局显示样式appearance proxy
appearance是apple在iOS5.0上加的一個協議,它讓程序員可以很輕松地改變某控件的全局樣式(背景)一般向導航欄navigationBar和狀態欄tabBar的整體樣式的設置使用這個方法,在所有的控制器加載之前設置,即在delegate中,單個控制器不同的設置需要在相應的控制器中進行設置。
@selector(appearance)
支持UIAppearance協議的類可以訪問appearance selector ,它為receiver返回appearance proxy,我么可以給proxy發一些消息,諸如setTintColor:等
但是它并不是支持所有的UI類。下面列出它支持的類
1.UIActivitiIndicatorView
2.UIBarButtonItem
3.UIBarItem
4.UINavgationBar
5.UIPopoverControll
6.UIProgressView
7.UISearchBar
8.UISegmentControll?
9.UISlider
10.UISwitch
11.UITabBar
12.UITabBarItem
13.UIToolBar
14.UIView
15.UIViewController
例如:
?[[UINavigationBarappearance] setTintColor:[UIColorblackColor]];
?[[UISearchBarappearance] setTintColor:[UIColorblackColor]];
注意:
初學者肯定會任意調用方法,大部分方法時無效的,如果調用時會拋出unknown selector 異常
那么如何查看你調用的方法時有效的呢,我們可以在此類的頭文件中查看包含“UI_APPEARANCE_SELECTOR”常量的方法。
?
例如UIToolBar
它支持下列方法
@property(nonatomic,retain) UIColor ? *tintColor? UI_APPEARANCE_SELECTOR;
- (void)setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (UIImage *)backgroundImageForToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (UIImage *)shadowImageForToolbarPosition:(UIToolbarPosition)topOrBottom NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
?
了解更多請訪問:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html。
轉載于:https://www.cnblogs.com/yipingios/p/5531067.html
總結
以上是生活随笔為你收集整理的设置控件全局显示样式appearance proxy的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 之Count and
- 下一篇: row_number() over(pa