2012-11-18 160 views
0

任何人都可以快速帮助我吗?我一直在玩这个小时,不明白为什么这不起作用?UILabel突出显示文字

我试图更新选定标签中的突出显示的文本(这是在UILabels之前定义的数组中引用)。

该方法由视图界面中来自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]; 

...最后一行。仍然不起作用。

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

回答

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; 
}