gpt4 book ai didi

ios - 无法从 UIViewController 访问 UIView 的 UIColor 属性

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:37 26 4
gpt4 key购买 nike

尝试在主 UIViewController 的 UIView 子类上设置 UIColor 变量。我有一个用于检索 UIViewController 中请求的颜色的属性,我有一个用于在 UIView 上接收的颜色的属性。但是,当我使用点方法应用检索到的颜色时,出现错误“在类型为‘UIView *’的对象上找不到属性‘brushColor’”

//Controller.h

@interface ViewController : UIViewController {
UIColor *colorPicked;
UIView *drawScreen;
}
@property (nonatomic, strong) UIView *drawScreen;

@property (nonatomic, strong) UIColor *colorPicked;

//Controller.m

@implementation ViewController

@synthesize drawScreen;
@synthesize colorPicked;

- (void)viewDidLoad{
self.drawScreen = [[DrawingView alloc] initWithFrame:CGRectMake(0, 44, 1024, 724)];
drawScreen.backgroundColor = [UIColor clearColor];

drawScreen.brushColor = self.colorPicked; //This line errors stating the property is not available on type (UIView *)

[self.view addSubview:drawScreen];


[super viewDidLoad];
}

// View .h

@interface DrawingView : UIView{

UIColor *brushColor;

UIBezierPath *myPath;
}


@property (nonatomic, retain) UIColor *brushColor;

@end

// View .m

@implementation DrawingView

@synthesize brushColor;

- (void)drawRect:(CGRect)rect{

myPath = [[UIBezierPath alloc] init];

[brushColor setStroke];

[myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];

}

@end

最佳答案

您已将 drawScreen 声明为 UIView,将其在 .h 中的声明更改为

@property (nonatomic, strong) DrawingView *drawScreen;

并更改 ivar 声明以匹配(或完全删除它,因为您无论如何都在使用属性)

关于ios - 无法从 UIViewController 访问 UIView 的 UIColor 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11820096/

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