简体   繁体   中英

UITableViewCell Font size does not change

I have a custom UITableViewCell that is being displayed in tableView. This UITableViewCell is generated from a nib file. The UITableViewCell has a UILabel in it.The code of this is given below.Apparently I have tried to decrease the font size to a fixed size and nothing seems to work.Here is what I am currently doing to set the font size.

In the UITableViewCell (this is the .m file attached to the nib) here is what I do

- (void)awakeFromNib
{
    UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 4.0 ];
        self.LabelMyLabel.font  = myFont;
}

This is how the TableView is being created

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *TransferIdentifier = @"TransferTableItem";

    FileTransferTableCell *cell = [tableView dequeueReusableCellWithIdentifier:TransferIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FileCustomTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    //Set the text in the UITableViewCell here
    cell.textLabel.text = [self.MyArray objectAtIndex:indexPath.row];
    return cell;
}

I would appreciate it if anyone could help me figure out why my textsize is always constant (I have also decreased the font size of the label in UITableViewCell in interface builder) ?

The setting of the label's font is working. The problem is that you are setting the text of the wrong label. You are saying:

cell.textLabel.text = [self.MyArray objectAtIndex:indexPath.row];

That's the wrong label. You want to set the text of LabelMyLabel , not textLabel . They are two different labels.

更改cell.textLabel.textcell.LabelMyLabel ,因为它是建立在你的笔尖。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM