自定义控件能实时查看

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/blackeynes/article/details/79870883

自定义控件实时查看

  • 创建一个xib文件关联某个view
  • 在view定义哪里添加IB_DESIGNABLE
IB_DESIGNABLE
@interface xxView ()
@end
  • 图片不显示是由于bundel问题,写个UIImage的分类
+ (UIImage *)imageWithNamed:(NSString *)name bundleForClass:(Class)cls {
    NSBundle *bundle;
#if TARGET_INTERFACE_BUILDER
    bundle = [NSBundle bundleForClass:cls];
#else
    bundle = [NSBundle mainBundle];
#endif
    return [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
}

猜你喜欢

转载自blog.csdn.net/blackeynes/article/details/79870883