我想知道如何动态地将imageview设置到tableview单元的中心。
这是我目前的代码。
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100,100, 20, 20)];
imgView.image = [UIImage imageNamed:@"friendsCelluserpic.png"];
cell.imageView.image = imgView.image;
答案 0 :(得分:1)
试试这段代码: 这将使您的图像在TableViewCell中水平居中对齐
float imgwidth=40;
float imgheight=40;
imgView = [[[UIImageView alloc] initWithFrame:CGRectMake((cell.contentView.bounds.size.width/2)-(imgwidth/2),15, imgwidth, imgheight)] autorelease];
[cell.contentView addSubview:imgView];
答案 1 :(得分:1)
试试这个,:))
UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"friendsCelluserpic.png"]];
imgView.frame=CGRectMake(100, 100, 20, 20);
[cell.contentView addSubview:imgView];
return cell;
答案 2 :(得分:0)
您可以像[cell.contentView addSubview:imgView];