SDK11 新特性之ColorNamed

来源:互联网 发布:淘宝下载安装2015旧版 编辑:程序博客网 时间:2024/06/05 07:37

he definition for a named color that can be used anywhere you can use a color in your project.

1、能够同时在代码和IB中使用别名访问颜色
+ (nullable UIColor )colorNamed:(NSString )name NS_AVAILABLE_IOS(11_0); // load from main bundle
+ (nullable UIColor )colorNamed:(NSString )name inBundle:(nullable NSBundle )bundle compatibleWithTraitCollection:(nullable UITraitCollection )traitCollection NS_AVAILABLE_IOS(11_0);
在IB中可以直接在右侧属性tab上选择对应的asset名
创建和使用起来很方便,如下图。
在assets中创建颜色
目录结构如下
在IB中使用时 直接选择namedcolors 就是assets中的颜色列表
可以直接方便的访问 如果是bundle不是mainbundle的话 需要调用那个长的方法
2、只能兼容iOS11 以后的版本,并且加过nameColor的IB文件 在XCode8上不能够打开,就是这个功能 无论是Xcode版本还是ios系统版本是不向下兼容的。
3、综上,很好用,但是目前很鸡肋。

原创粉丝点击