iOS 设置控件全局显示样式appearance proxy

appearance是apple在iOS5.0上加的一个协议,它让程序员可以很轻松地改变某控件的全局样式(背景

    [[UITabBarItem appearance] setTitleTextAttributes:
            @{NSForegroundColorAttributeName : [UIColor grayColor]}
            forState:UIControlStateNormal];
  //设置tabbarite的正常状态下的颜色

  // 05a3bb
    UIColor *selTextColor = [UIColor colorWithRed:0x05/255.0 green:0xa3/255.0 blue:0xbb/255.0 alpha:1];
    [[UITabBarItem appearance] setTitleTextAttributes:
            @{NSForegroundColorAttributeName : selTextColor}
            forState:UIControlStateSelected];

  //设置tabbarite的被选中状态下的颜色

  @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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值