开发者

Custom UITableViewCell label font problems

开发者 https://www.devze.com 2023-02-18 00:14 出处:网络
So I\'ve got a custom UITableViewCell created in a nib file in IB, very basic it has got an imageview, and two labels for now.I\'ve got the table populating with the correct cells in their correct siz

So I've got a custom UITableViewCell created in a nib file in IB, very basic it has got an imageview, and two labels for now. I've got the table populating with the correct cells in their correct sizes and everything, but there is one slight problem. For some reason, the font size of the first label is changing from cell to cell. Sometimes i开发者_运维问答t is the same font size as the second label, sometimes it is the default font size. This is strange because it preserves the font color and positioning, just the size is wrong.

Anyone know what is going on here?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger row = [indexPath row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [self loadCell];
    }
    NSDictionary *event = [eventsArray objectAtIndex:row];
    EventTableCell *eventCell = (EventTableCell*)cell;
    eventCell.mainLabel.text = [event valueForKey:@"Title"];
    eventCell.subLabel.text = [event valueForKey:@"Time"];
    return eventCell;
}

the second label always has the correct font size though.


By default, UILabels have an option in IB "Adjust to Fit." What this does, is it changes the font size to make your content fit within the allotted size. It may just be a coincidence that it sizes down to the same font size as your second UILabel.

0

精彩评论

暂无评论...
验证码 换一张
取 消