- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"UITableViewCell"];
//set the cell's text....
UIProgressView *prg =[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
prg.tag = indexPath.row + 1000;
prg.frame = CGRectMake(0, (cell.frame.size.height - prg.frame.size.height), cell.frame.size.width, 10);
[prg setTintColor:[UIColor colorWithRed:68/255.0 green:183/255.0 blue:104/255.0 alpha:1.0]];
[cell addSubview:prg];
return cell;
}
這適用於iPhone - 進度視圖與單元寬度相同,但在iPad上(這是通用應用程序),它只有單元的一半寬。我該如何解決?如果您使用自動佈局你最好儘量避免幀儘可能如何在與單元寬度相同的UITableViewCell中插入UIProgressView?
prg.autoresizingMask = UIViewAutoresizingFlexibleWidth;
我在嘗試時遇到這種情況:無法解析約束格式:無法解釋'|'字符,因爲相關視圖沒有超級視圖 | [progressView] | – croceldon 2014-10-28 19:22:25
@croceldon在添加約束之前,您必須添加子視圖。 [cell.contentView addSubview:prg]; – BooRanger 2014-10-29 08:21:00