无法从UIViewController访问UIView的UIColor属性

时间:2012-08-05 21:08:36

标签: ios xcode uiview properties uiviewcontroller

尝试从主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

1 个答案:

答案 0 :(得分:5)

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

@property (nonatomic, strong) DrawingView *drawScreen;

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