UILabel突出显示文本

时间:2012-11-18 00:02:52

标签: uilabel highlighting

有人能快点帮帮我吗?我已经玩了几个小时了,不明白为什么这不起作用?

我正在尝试更新所选标签中的突出显示文字(在之前定义的UILabel数组中引用)。

此方法由视图界面中的UISlider接收IBAction调用。

但是,当我从数组中检索选定的UILabel对象并设置其HIGHLIGHTED属性时,视图界面上没有相应的反应。我的印象是它应该使用下面的代码自动重绘用文本突出显示的视图。

PS:我的连接似乎都是正确的Interface Builder(即IBOutlet UILabels正确映射/连接,触发此方法的UISlider通过IBAction连接)。

我错过了什么吗?

- (IBAction) changeHighlightedLabel: (id)sender
{

// Setup
UILabel *selectedLabel = [[UILabel alloc] init];
selectedLabel.highlightedTextColor = [UIColor greenColor];

// Interpret slider value and round to integer
UISlider *temp = sender;
float unroundedTempValue = [temp value];
float roundedTempValue = roundf(unroundedTempValue);

// Select the UILabel object from the UI Label array based on slider valuer
selectedLabel = [uiLabelArray objectAtIndex:roundedTempValue];

// Highlight the selected label
selectedLabel.highlighted = YES;

}

我也试过替换......

    selectedCountryLabel = [[uiCountryLabelArray objectAtIndex:roundedTempValue] isHighlighted];

...为最后一行。仍然无效。

有任何反馈或帮助吗?感谢。

1 个答案:

答案 0 :(得分:2)

您正在创建UILabel并首先设置highlightedTextColor属性,然后使用数组中的UILabel覆盖该属性。由于您这次没有设置任何highlightedTextColor,因此highlighted属性不适用于标签。

按如下方式更改。

- (IBAction) changeHighlightedLabel: (id)sender
{

   // Interpret slider value and round to integer
   UISlider *temp = sender;
   float unroundedTempValue = [temp value];
   float roundedTempValue = roundf(unroundedTempValue);

   // Select the UILabel object from the UI Label array based on slider valuer
   selectedLabel = [uiLabelArray objectAtIndex:roundedTempValue];

   // Highlight the selected label
   selectedLabel.highlightedTextColor = [UIColor greenColor];
   selectedLabel.highlighted = YES;
}