我添加了带标签的自定义UItableViewCell
。标签在iOS 6中可见,但在iOS 7中不可用。
-(void)layoutSubviews{
[super layoutSubviews];
self.textLabel.frame = CGRectMake(90.0f ,-5.0f, 200.0f, 50.0f);
self.imageView.frame = CGRectMake(3.0f , 2.0f, 75.0f, 55.0f);
}
-(void)drawRect:(CGRect)rect{
self.imageView.layer.cornerRadius = 5;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderColor = [UIColor colorWithRed:0.0 green:0.4 blue:0.7 alpha:0.9].CGColor;
self.imageView.layer.borderWidth = 2;
[self.textLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
self.textLabel.backgroundColor = [UIColor clearColor];
[[UIColor grayColor] set];
[videoDurationTextLabel drawInRect:CGRectMake(90, 30, 190, 10) withFont:[UIFont fontWithName:@"Helvetica" size:12]];
[videoFileSizeLabel drawInRect:CGRectMake(170, 30, 190, 15) withFont:[UIFont fontWithName:@"Helvetica" size:12]];
}
TableViewController类
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"LazyTableCell";
VideoCustomCell *cell = [self.tblView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[VideoCustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = videoRecord.videoTitle;
cell.videoFileSizeLabel = [NSString stringWithFormat:@"%.4lfMb",totalSpaceInMB];
[cell.imageView setImage:[UIImage imageWithData: imgData]];
cell.videoDurationTextLabel = videoRecord.duration;
}
答案 0 :(得分:1)
试试这段代码。
- (void) layoutSubviews {
[super layoutSubviews];
CGRect cvb = self.contentView.bounds;
CGRect imf = self.imageView.frame;
imf.origin.x = cvb.size.width - imf.size.width;
self.imageView.frame = imf;
CGRect tf = self.textLabel.frame;
tf.origin.x = 5;
self.textLabel.frame = tf;
}
- (void) viewDidLoad {
[super viewDidLoad];
UINib *cellNib = [UINib nibWithNibName:@"CustomTableCell" bundle:[NSBundle mainBundle]];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"CustomTableCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomTableCell";
CustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.titleLabel.text ="test text";
[cell.imageView setImage:[UIImage imageWithData: imgData]];
return cell;
}
答案 1 :(得分:1)
您必须使用单元格标识符名称命名自定义单元格。
正如我在UITableViewCell
代码中看到的,您的小区标识符名称为LazyTableCell
。将您的单元格重命名为同名。