nhiều người sử dụng các kỹ thuật của việc thêm các nhãn như subviews của các tế bào, và có thể bạn chạy vào kết quả bất ngờ với việc tái sử dụng các tế bào. Apple đã cung cấp các mẫu có thể được tùy chỉnh theo mọi khía cạnh. Trong trường hợp của bạn, mà không sử dụng các ô tùy chỉnh và không thêm nhãn, tôi sẽ sử dụng mẫu UITableViewCellStyleValue2
, bạn có thể chơi với các nhãn hiện tại và phụ kiệnView, như cell.textLabel
, cell.detailTextLabel
và cell.accessoryView
, xem đoạn mã này mô phỏng ít hoặc nhiều giao diện của bạn:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.contentMode=UIViewContentModeScaleToFill;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
cell.textLabel.textAlignment=UITextAlignmentCenter;
cell.textLabel.font=[UIFont boldSystemFontOfSize:22];
cell.textLabel.textColor=[UIColor lightGrayColor];
cell.detailTextLabel.contentMode=UIViewContentModeScaleToFill;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
cell.detailTextLabel.textAlignment=UITextAlignmentLeft;
cell.detailTextLabel.font=[UIFont boldSystemFontOfSize:23];
cell.detailTextLabel.textColor=[UIColor blackColor];
[email protected]"Tel.:";
[email protected]"+3912345678";
UIImageView *imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"phone.png"]];
cell.accessoryView = imageView;
[imageView release];
return cell;
}
Hy vọng điều này sẽ hữu ích.
Bạn luôn có thể phân lớp UITableViewCell và hai UILabels cho nó. – tilo