Размер шрифта UITableViewCell не меняется - PullRequest
2 голосов
/ 12 января 2011

Я пытаюсь уменьшить размер шрифта на моем UITableViewCell.Вот код, который у меня есть:

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* CellIdentifier = @"Cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

    UILabel *nameLabel; 
    UISwitch *mySwitch;
    if ( cell == nil ) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault 
                                       reuseIdentifier: CellIdentifier] autorelease];

        nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake( 220, 13, 100, 20 )] autorelease];
        nameLabel.tag = 22;
        nameLabel.font = [UIFont boldSystemFontOfSize: 5.0];
        nameLabel.textColor = [UIColor blueColor];
        nameLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
        nameLabel.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview: nameLabel];

        mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
        mySwitch.tag = ((400*(indexPath.section+1))+indexPath.row);
        [mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
        [cell addSubview:mySwitch];
        cell.accessoryView = mySwitch;


    }
    else {
        nameLabel = (UILabel*)[cell.contentView viewWithTag: 22];
        mySwitch = (UISwitch *)[cell.contentView viewWithTag:((400*(indexPath.section+1))+indexPath.row)];
    }

    nameLabel.textLabel.text = @"Hello";


}

Но шрифт метки определенно не выходит за размер 5. Это обычный шрифт и нормальный размер, вероятно, примерно 12 размера шрифта, или любой другой по умолчанию,Почему я не могу изменить размер шрифта?

Ответы [ 2 ]

2 голосов
/ 12 января 2011

Не имеет отношения к вашей проблеме, но нет необходимости добавлять переключатель в качестве подпредставления.Настройка вспомогательного вида должна добавить его в ячейку и сохранить его.

    [cell addSubview:mySwitch];
    cell.accessoryView = mySwitch;

... должно быть просто ...

    [cell setAccessoryView:mySwitch];
0 голосов
/ 12 января 2011

Попробуйте это

Вместо nameLabel.textLabel.text = @"Hello";

Использование

nameLabel.text = @"Hello";
...