UITableViewCell Display multiple fonts

后端 未结 4 1973
天命终不由人
天命终不由人 2021-01-28 13:50

I want to display two words in the uitableviewcell in different fonts similar to the iPhone Address Book. Ex: John Buchanan

相关标签:
4条回答
  • 2021-01-28 14:34

    Make custom UITableViewCell.

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
            }
    
            //Initialize String for Displaying
            //NSString *str = 
    
            UILabel *lbl;
            if ([cell.contentView.subviews count] == 0) {
    
                //Label alloc and init with frame
                //lbl = [[UILabel] alloc] initWithFrame:CGRectMake(x,y,width,height)];
    
                //Cofigure Label (text, font, etc.)
                lbl.text = str;
                //lbl.font = font;      
    
                //Add subview
                [cell.contentView addSubview:lbl];
    
                //Release
                [lbl release];
            }
            else {
                lbl = [cell.contentView.subviews objectAtIndex:0];
    
                lbl.text = str; //Do only set variable value.
            }
    
            return cell;
        }
    
    0 讨论(0)
  • 2021-01-28 14:36

    Jack Use cell.textLabel.text and cell.textLabel.DetailText.. These are two label in one cell..

    0 讨论(0)
  • 2021-01-28 14:44

    Either you should use two UILables, or you can use OHAttributedLabel to draw NSAttributedString..

    EDIT:

    You can change the UILabel size dynamically using,

    CGSize expectedLabelSize = [titleLabel.text sizeWithFont:titleLabel.font]; 
    titleLabel.frame = CGRectMake(xBase, yBase, expectedLabelSize.width, expectedLabelSize.height);
    
    0 讨论(0)
  • 2021-01-28 14:55

    For each of the label create the font and apply to the font property of that label.

    + (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize
    
    0 讨论(0)
提交回复
热议问题