尝试从主UIViewController在UIView子类上设置UIColor变量。我有一个属性来检索UIViewController中请求的颜色,我有一个属性,可以在UIView上接收颜色。但是,当我使用点方法应用检索到的颜色时,我得到一个错误“属性”brushColor“找不到类型为'UIView *'的对象”
//或者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
答案 0 :(得分:5)
您已将drawScreen
声明为UIView
,请将.h中的声明更改为
@property (nonatomic, strong) DrawingView *drawScreen;
并更改ivar声明以匹配(或完全删除它,因为您仍在使用属性)