UITableViewCell Display multiple fonts

后端 未结 4 2012
天命终不由人
天命终不由人 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;
        }
    

提交回复
热议问题