- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.section == 0) {
cell.accessoryType = UITableViewCellAccessoryNone;
if (indexPath.row == 0) {
cell.textLabel.text = NSLocalizedString(@"Username", @"");
account = [self createNewLabel];
account.text = @"this is xyz doing some work in xyz, xyz is also working with me and we are doing great work, We hope to continue good work in future and make this company in good position. I wanted to stayed in this company for long time to take this company in high value";
[cell.contentView addSubview:account];
}
if (indexPath.row == 1) {
cell.textLabel.text = NSLocalizedString(@"Password", @"");
contact = [self createNewLabel];
[cell.contentView addSubview:contact];
}
}
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.textLabel.textColor = [UIColor blackColor];
return cell;
}
如何在单元格内容视图中调整帐户标签文本,将有许多部分和许多数据不同
答案 0 :(得分:1)
你去吧
+ (CGFloat) getHeightOfString:(NSString*)string withSize:(CGFloat)size andWidth:(CGFloat)width
{
CGSize boundingSize = CGSizeMake(width, CGFLOAT_MAX);
CGSize stringSize = [string sizeWithFont:[UIFont systemFontOfSize:size] constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
return stringSize.height;
}
上面的方法给出了文本的高度,这个高度可以设置为单元格中的标签。该方法需要标签的宽度,字体大小和文本。
为了动态实现标签高度,您需要处理行的高度。因此在设置rowHeight时,在tableView的委托方法中,您需要计算它们的高度和设置。而且在cellForRow方法中,您需要计算高度和设置。
您还需要动态计算行数,通常是
int numberOfLines = height/18; // or try height/19
它应该完美无缺。
由于
答案 1 :(得分:0)
试试这个:
NSString *lblText = @"YOUR STRING";
CGSize lblSize = [lblText sizeWithFont:[UIFont italicSystemFontOfSize:17] constrainedToSize:CGSizeMake(930, 500) lineBreakMode:UILineBreakModeWordWrap];
CGRect frame = account.frame;
frame.size.height = lblSize.height;
account.frame = frame;