加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – IB_DESIGNABLE,在预览中显示视图?

发布时间:2020-12-14 19:25:33 所属栏目:百科 来源:网络整理
导读:我在界面构建器中显示了我的IB_DESIGNABLE属性集的视图,但是当我使用预览功能查看我的视图在各种设备上的外观时,我只获得超级视图名称,例如UIView的. 不要在预览中显示IB_DESIGNABLE视图吗? 编辑按要求的代码屏幕截图: H=#import UIKit/UIKit.hIB_DESIGNAB
我在界面构建器中显示了我的IB_DESIGNABLE属性集的视图,但是当我使用预览功能查看我的视图在各种设备上的外观时,我只获得超级视图名称,例如UIView的.

不要在预览中显示IB_DESIGNABLE视图吗?

编辑按要求的代码屏幕截图:

H
=
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface TitleBannerView : UILabel
@property (nonatomic) IBInspectable CGFloat borderWidth;
@property (nonatomic) IBInspectable CGFloat cornerRadius;
@property (nonatomic) IBInspectable CGFloat shadowHeight;
@end

M
=
@implementation TitleBannerView
@synthesize borderWidth;
@synthesize cornerRadius;
@synthesize shadowHeight;

- (void)drawRect:(CGRect)rect {

    if (self.borderWidth == 0) self.borderWidth = 8.5;
    if (self.cornerRadius == 0) self.cornerRadius = 33;
    if (self.shadowHeight == 0) self.shadowHeight = 15.1;

    CGContextRef context = UIGraphicsGetCurrentContext();

    //// Color Declarations
    UIColor* bG = [UIColor colorWithRed: 0.18 green: 0.8 blue: 0.443 
       alpha: 1];
    UIColor* borderColor = [UIColor colorWithRed: 0.557 green: 0.267 blue: 0.678 
       alpha: 1];
    UIColor* shadowColor2 = [UIColor colorWithRed: 0.976 green: 0.859 blue: 0.718 
       alpha: 1];

    //// Shadow Declarations
    UIColor* shadow = shadowColor2;
    CGSize shadowOffset = CGSizeMake(-4.1,self.shadowHeight);
    CGFloat shadowBlurRadius = 1.5;

//

//// Frames
    CGRect frame = self.bounds;

    //// Subframes
    CGRect group = CGRectMake(CGRectGetMinX(frame) + 15,CGRectGetMinY(frame) + 15,CGRectGetWidth(frame) - 28,CGRectGetHeight(frame) - 40);


    //// Abstracted Attributes
    CGFloat roundedRectangleStrokeWidth = self.borderWidth ;
    CGFloat roundedRectangleCornerRadius = self.cornerRadius;

    //// Group
    {
        //// Rounded Rectangle Drawing
        UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: 
           CGRectMake(CGRectGetMinX(group) + floor(CGRectGetWidth(group) * 0.00060) + 0.5,CGRectGetMinY(group) + floor(CGRectGetHeight(group) * 0.00568) + 0.5,floor(CGRectGetWidth(group) * 0.99940) - floor(CGRectGetWidth(group) * 0.00060),floor(CGRectGetHeight(group) * 0.99432) - floor(CGRectGetHeight(group) * 0.00568)) 
         cornerRadius: roundedRectangleCornerRadius];
        CGContextSaveGState(context);
        CGContextSetShadowWithColor(context,shadowOffset,shadowBlurRadius,shadow.CGColor);
        [bG setFill];
        [roundedRectanglePath fill];
        CGContextRestoreGState(context);

        [borderColor setStroke];
        roundedRectanglePath.lineWidth = roundedRectangleStrokeWidth;
        [roundedRectanglePath stroke];

    }
}
@end

TitleBannerView是绿色的视图,带有紫色边框.

enter image description here

解决方法

首先,IBDesignable可以在预览中看到.

您是否在框架中声明了IBDesignable类? IBInspectable ONLY仅支持在框架中声明时的预览.

另外,请记住(不是你的情况):

>你的抽奖代码应该足够快,你只有100毫秒的抽奖时间.>经常需要prepareForInterfaceBuilder()方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读