嗨,我是iOS的新手。
我已经在ViewController1中实现了一个tableview.tableview我正在显示单元格的标题,detailText和公开指示器。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:MyIdentifier];
}
cell.textLabel.text =[listTableArray objectAtIndex:indexPath.row];
cell.textLabel.textColor=[UIColor grayColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.detailTextLabel.text=@"4mile";
return cell;
}
一切正常,现在当我这样做时,我需要在公开指示符之前有一个图像
UIImageView *accessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
accessoryView.image=[UIImage imageNamed:@"list.png"];
cell.accessoryView = accessoryView;
披露指示器已替换为image。但是我需要两个图像以及披露指示器,而无需使用“自定义”单元格。
我该怎么做...?帮帮我。
谢谢
与到期日类似,但在时间上,我需要图像
UITableViewCell
具有固定的布局,具体取决于初始化时使用的样式。您无法更改该布局,因为该单元会按其喜欢的方式布置其子视图。
- (void)layoutSubviews
像这样添加到您的单元格子类:
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake(0.0f , 0.0f, 20.0f, 20.0f);
}
否则尝试这个
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"list.png"];;
[imageView setFrame:CGRectMake(50, 5, 20, 20)]; // customize the frame
[cell.contentView addSubview:imageView];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句