我想根据我在另一个类中设置的属性来设置视图的backgroundColor。视图类部分看起来像这样:从UIColor属性设置UIView的backgroundColor的问题
// Interface iVar and property
UIColor * coverColor;
@property (nonatomic, retain) UIColor * coverColor;
// Where I set up the view
CGRect cover = CGRectMake(19.0, 7.0, coverWidth, coverHeight);
UIView * coverView = [[UIView alloc] initWithFrame:cover];
coverView.layer.cornerRadius = 5;
coverView.backgroundColor = coverColor;
[self.contentView addSubview:coverView];
[coverView release];
coverView = nil;
// In my other class where I try to set the color
cell.coverColor = noteblock.color;
// noteblock is a instance of a custom model (NSManagedObject) class. It have a property called color. The type is set to Transformable. It looks like this:
@property (nonatomic, retain) UIColor * color;
@dynamic color;
// I set the color like this when I create new Noteblock objects:
newNoteblock.color = [[[UIColor alloc] initWithRed:255.0/255.0 green:212.0/255.0 blue:81.0/255.0 alpha:1] autorelease];
当我在模拟器中运行应用程序,没有颜色显示,它是透明的。有关如何解决这个问题的任何想法?
你在哪里传递颜色值来这里coverColor财产?你真的获得了存储在tat中的价值吗? chk使用NSLog ... – booleanBoy
当我运行NSLog(@“%@”,noteblock.color); (存储在数据库中的颜色)我得到以下输出:UIDeviceRGBColorSpace 1 0.831373 0.317647 1. – Anders