我想根據我在另一個類中設置的屬性來設置視圖的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