3

尝试在主 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
4

1 回答 1

5

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

@property (nonatomic, strong) DrawingView *drawScreen;

并更改 ivar 声明以匹配(或完全删除它,因为您仍然使用属性)

于 2012-08-05T21:11:38.180 回答