【问题标题】:Sse IBInspectable and IB_DESIGNABLE Bug changes not show in storyboard?Sse IBInspectable 和 IB_DESIGNABLE 错误更改未显示在情节提要中?
【发布时间】:2016-02-25 02:38:49
【问题描述】:

我阅读了这篇文章IBInspectable / IBDesignable 和流程步骤,但我发现更改没有立即呈现在情节提要上。有人知道为什么吗? 我的 Xcode 版本:7.1

我的主要代码:

ViewController.h

#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface ViewController : UIViewController


@end

UIView+CornerRadius.h

#import <UIKit/UIKit.h>

@interface UIView (CornerRadius)
@property(nonatomic ,assign) IBInspectable CGFloat cornerRadius;
@end

UIView+CornerRadius.m

#import "UIView+CornerRadius.h"

@implementation UIView (CornerRadius)

-(void)setCornerRadius:(CGFloat)cornerRadius {
    self.layer.cornerRadius = cornerRadius;
    self.layer.masksToBounds = cornerRadius > 0;
}

-(CGFloat)cornerRadius {
    return  self.layer.cornerRadius;
}

@end

【问题讨论】:

    标签: xcode ibdesignable ibinspectable


    【解决方案1】:

    我已经在 Xcode 中测试了你的代码,我发现如果你将 storyboard 上的视图声明为 UIView+CornerRadius 的实例,它真的不起作用。但是如果你创建一个 UIView 或你的 UIView+CornerRadius 类别的子类,并将视图声明为这个子类,它就可以正常工作。

    我将附上截图来演示:

    【讨论】:

    • 哦,分类里的代码和你的一模一样。而且你不需要在UIView的子类CornerView中写任何代码
    猜你喜欢
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 2012-05-18
    • 2015-08-21
    • 1970-01-01
    相关资源
    最近更新 更多