zoukankan      html  css  js  c++  java
  • UI_APPEARANCE_SELECTOR 延伸

    iOS后属性带UI_APPEARANCE_SELECTOR 可以统一设置全局作用

    例如:

    1>开关控件

    @property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR

    可以统一设置开关的onTintColor样式.不过开关控件的颜色属性比较特殊

    1.只在添加时作用一次.

    2.添加结束后.

    3.以后设置便不再改变.

    4.也可以移出开关的父控件.而把开关从新加入到window上.

    在iOS属性后有UI_APPEARANCE_SELECTOR标志都可以一次性统一设置.这种情况还有很多.比如说统一设置UITabbarItem的文字颜色 方法如下:

    - (void)setTitleTextAttributes:(nullable NSDictionary*)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

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

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

    补上实例代码:

    + (void) initialize

    {

        if (self == [DACircularProgressView class]) {

            DACircularProgressView *circularProgressViewAppearance = [DACircularProgressView appearance];

            [circularProgressViewAppearance setTrackTintColor:[[UIColor whiteColor] colorWithAlphaComponent:0.3f]];

            [circularProgressViewAppearance setProgressTintColor:[UIColor whiteColor]];

            [circularProgressViewAppearance setInnerTintColor:nil];

            [circularProgressViewAppearance setBackgroundColor:[UIColor clearColor]];

            [circularProgressViewAppearance setThicknessRatio:0.3f];

            [circularProgressViewAppearance setRoundedCorners:NO];

            [circularProgressViewAppearance setClockwiseProgress:YES];

            

            [circularProgressViewAppearance setIndeterminateDuration:2.0f];

            [circularProgressViewAppearance setIndeterminate:NO];

        }

    }

     

     

    更多:

    1.http://blog.csdn.net/lxl_815520/article/details/51360878

    2.https://southpeak.github.io/2015/07/20/cocoa-uikit-uiapearance/

    3.https://www.cnblogs.com/Rinpe/p/5351639.html

    4.https://www.cnblogs.com/salam/archive/2013/01/30/appearance.html

     

  • 相关阅读:
    http协议介绍
    使用Bind提供域名解析服务
    .bash_profile和.bashrc的区别
    SNAT和DNAT
    9.Iptables与Firewalld防火墙
    ubuntu18.04.3新装系统安装QT5.14.1和环境配置
    【Navicat】如何激活成永久版本
    windows 安装配置mysql 8,以及远程连接访问
    fork子进程父进程死掉之后,getppid()不为1的解决办法
    ubuntu64运行32位程序安装过程
  • 原文地址:https://www.cnblogs.com/Jenaral/p/6166132.html
Copyright © 2011-2022 走看看