gpt4 book ai didi

ios - IB_DESIGNABLE,在预览中显示 View ?

转载 作者:可可西里 更新时间:2023-11-01 04:41:09 26 4
gpt4 key购买 nike

我在界面生成器中显示了我的 View ,并设置了我的 IB_DESIGNABLE 属性,但是当我使用预览功能查看我的 View 在各种设备上的外观时,我只获得了 super View 名称,例如UIView.

预览中不显示 IB_DESIGNABLE View 吗?

根据要求编辑代码+屏幕截图:

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 是带有紫色边框的绿色 View 。 enter image description here

最佳答案

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

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

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

  1. 您的绘制代码应该足够快,您只有 100 毫秒的绘制时间。

  2. prepareForInterfaceBuilder() 方法是经常需要的。

关于ios - IB_DESIGNABLE,在预览中显示 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33479391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com