2010-03-17 42 views
1

我有过简单的UI按钮分配一个值麻烦:对象不能设置 - 无论是只读属性或没有setter发现

//Assume rect is defined 
rect = CGRectMake(13, 10, 48, 48); 
profileButton = [[UIButton alloc] initWithFrame:rect]; 
profileButton.buttonType = UIButtonTypeCustom; 

我收到“对象不能设置 - 要么只读当试图将buttonType分配给UIButtonTypeCustom时,只有属性或setter发现“。

回答

5

这是因为buttonType是一个只读属性。您只能使用buttonWithType:创建特定类型的按钮。

profileButton = [[UIButton buttonWithType: UIButtonTypeCustom] retain]; 
profileButton.frame = CGRectMake(13, 10, 48, 48); 

(不知道什么是profileButton,但假设它不是一个固定属性)

+0

该诀窍。初始化时我需要记住这一点。谢谢! –

相关问题