2013-06-05 53 views
0

下面的UITableView单元格根据搜索类型交替文本位置。文本标签设置为标准,详细信息文本当前设置为斜体。我希望这是相反的。基于查询格式的UITableView单元格文本字体

即如果genusSpecies:animal.commonName然后为textLabel = ItalicFont否则如果animal.commonName:genusSpecies然后为textLabel = StandardFont

我想这个规则应用到下面的代码。

- (void)setAnimal:(ITanimal *)animal forType:(ITSectionType)type { 
    _animal = animal; 

    BOOL isCommonType = (type == ITSectionTypeCommonName); 
    NSString *genusSpecies = animal.species]; 

    [self.textLabel setFont:ItalicFont]; 
    [self.textLabel setText:(!isCommonType)? genusSpecies : animal.commonName]; 

    [self.detailTextLabel setFont:StandardFont]; 
    [self.detailTextLabel setText:(!isCommonType)? animal.commonName : genusSpecies]; 

} 
+0

问题是什么?只需将相同类型的条件表达式添加到标签文本设置的字体设置中,即可完成。它很丑,但很有用。 – allprog

+0

我已经调整了上面的问题,使其更清晰。 – Steve

+0

'if genusSpecies:animal.commonName ...'是什么意思?我很确定这些表达式没有':'运算符。是不是有任何机会? – allprog

回答

0

的问题是有点含糊,但我的感觉是,你必须在地方几乎一切。只需创建一个BOOL,您可以使用它来决定是否显示属物种。就像这样:

BOOL isGenuSpecies = (boolean expression to decide if this is a genus species) 

UIFont *textLabelFont = isGenusSpecies? StandardFont : ItalicFont; 
UIFont *detailTextLabelFont = isGenusSpecies? ItalicFont : StandardFont; 

[self.textLabel setFont: textLabelFont]; 

[self.detailTextLabel setFont: detailTextLabelFont]; 

这工作只要你有StandardFontItalicFont先前定义somehere。

+0

谢谢,这样做! – Steve

0

为斜体,你可以使用

[UIFont fontWithName:@"Helvetica-Oblique" size:13.0] 
+0

这不是我问的问题的答案。我在问一个条件,字体样式已经设置好了。 – Steve

相关问题