1

我需要知道如何UILabel使用 KVC 设置文本颜色、字体、对齐方式等属性。在下面的链接中,有一个关于如何设置UIButton标题标签文本的示例。 如何使用 KVC 更改 UIButton 的标题?

鉴于此,我尝试过这样的:

NSDictionary *labelProperties = @{@"textColor":@"redColor", @"font":@"Helvetica"},@"frame":@"50,50,50,50", @"text":@"Hi....", @"backgroundColor":@"yellowColor"};
UILabel*myLabel = [[UILabel alloc]init];
[myLabel setValuesForKeysWithDictionary:labelProperties];
[self.view addSubview:myLabel];

但它没有用。应用程序崩溃了。我希望这是由于键的值不正确。值的格式应该是什么,以便上面的代码起作用。我需要像这样设置所有 UI 属性。

是否有任何教程可以让我了解如何设置值?

4

1 回答 1

1

当所需的实际值显然不是字符串时,您试图将所有值设置为字符串。

尝试这部分并从那里开始工作:

NSDictionary *labelProperties = @{@"textColor":[UIColor redColor]}
于 2013-05-30T07:10:53.677 回答