UITableViewCell作为进度指示器 [英] UITableViewCell as progress indicator
本文介绍了UITableViewCell作为进度指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试设置整个单元格背景视图以显示进度指示器.
I am trying to set the whole cell background view to show a progress indicator.
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
cell.backgroundView = progressView;
[progressView setFrame:cell.bounds];
}
这不会将进度条设置为整个单元格,而是仅设置单元格的顶部.我应该如何使细胞透明吗?我如何使用整个单元格背景以颜色填充显示进度,而单元格上的文本仍然可见?
this does not set the progress bar to the whole cell, but just the top part of the cell. Should I make the cell transparent some how ? How can I use the whole cell background to show progress with a color fill, while text on the cell remain visible ?
推荐答案
您需要设置UIProgressView的高度并将其添加为单元格的内容子视图,如下所示:
You need to set the height of your UIProgressView and add it as a content subview for you cell, like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
//setting height of progressView
CGAffineTransform transform = CGAffineTransformMakeScale(cell.frame.size.width, cell.frame.size.height);
progressView.transform = transform;
[cell.contentView addSubview:progressView];
//your text
cell.textLabel.text = @"Cell Text Label";
cell.detailTextLabel.text = @"Cell Detail Label";
}
return cell;
}
这篇关于UITableViewCell作为进度指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文