0

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

即如果 genusSpecies : animal.commonName 那么 textLabel = ItalicFont else if 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];

}
4

2 回答 2

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定义了此功能。

于 2013-06-05T09:33:10.817 回答
0

对于斜体字体,您可以使用

[UIFont fontWithName:@"Helvetica-Oblique" size:13.0]
于 2013-06-05T09:32:56.517 回答