尝试在主 UIViewController 的 UIView 子类上设置 UIColor 变量。我有一个用于检索 UIViewController 中请求的颜色的属性,并且我有一个用于在 UIView 上接收颜色的属性。但是,当我使用 dot 方法应用检索到的颜色时,我收到错误“在 'UIView *' 类型的对象上找不到属性“brushColor””
//控制器.h
@interface ViewController : UIViewController {
UIColor *colorPicked;
UIView *drawScreen;
}
@property (nonatomic, strong) UIView *drawScreen;
@property (nonatomic, strong) UIColor *colorPicked;
//控制器.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];
}
//查看.h
@interface DrawingView : UIView{
UIColor *brushColor;
UIBezierPath *myPath;
}
@property (nonatomic, retain) UIColor *brushColor;
@end
//查看.m
@implementation DrawingView
@synthesize brushColor;
- (void)drawRect:(CGRect)rect{
myPath = [[UIBezierPath alloc] init];
[brushColor setStroke];
[myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
@end