由於顯示名稱字符串的標籤定義了格式和樣式,如果您想要使用不同的樣式,則需要針對每種每種樣式都有不同的樣式。具體來說,您將需要一個用於名字的uilabel:firstNameLabel.font = [UIFont systemFontOfSize:12];
和一個用於姓氏:lastNameLabel.font = [UIFont boldSystemFontOfSize:12];
。
第一個名字字符串是firstNameLabel
,然後調用[firstNameLabel sizeToFit]
以使其中的標籤文本適合。然後使用firstNameLabel
的框架將lastNameLabel
直接放在它之後。
UILabel * firstNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10,100,25)];
firstNameLabel.tag = firstNameLabelTag //This should be a constant probably
firstNameLabel.font = [UIFont systemFontOfSize:12];
firstNameLabel.text = theStringRepresentingTheFirstName;
[firstNameLabel sizeToFit];
UILabel * lastNameLabel = [[UILabel alloc] initWithFrame:
CGRectMake(10+firstNameLabel.frame.size.width+2, 10, 100, 25)];
lastNameLabel.tag = lastNameLabelTag //This should be a constant probably
lastNameLabel.font = [UIFont boldSystemFontOfSize:12];
lastNameLabel.text = theLastNameString;.
[cell.contentView addSubview:firstNameLabel];
[cell.contentView addSubview:lastNameLabel];
至於分裂名稱字符串,你可能相當有限。我會分開第一個空格,並假設第一個字符串是最後一個字符(如在第一張圖片中)。
原理案例是相似的,你需要一個標籤爲你想呈現的每種風格。