UITableViewCell.imageView 的大小已随自动布局更改
size of UITableViewCell.imageView changed with autolayout
我在 uitableview 中使用 UITableViewCell.imageView 来显示图像和图像视图的圆角。使用以下代码
[cell2.imageView setAutoresizingMask:UIViewAutoresizingNone];
cell2.imageView.backgroundColor = [UIColor whiteColor];
cell2.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell2.imageView.layer.masksToBounds = YES;
cell2.imageView.clipsToBounds = YES;
cell2.imageView.layer.borderWidth = 1.0f;
cell2.imageView.layer.borderColor = [UIColor colorWithRed:(1/255.0) green:(146/255.0) blue:(219/255.0) alpha:1.0].CGColor;
[cell2.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[ReviewArrayMain objectAtIndex:indexPath.row] valueForKey:@"logo"]]] placeholderImage:[UIImage imageNamed:@"Defaultlogo.png"] options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (error) {
NSLog(@"Error : %@", error);
}else{
cell2.imageView.image = image;
[cell2 layoutSubviews];
cell2.imageView.layer.cornerRadius = cell2.imageView.frame.size.height/2;
}
}];
我在一个屏幕上的输出越来越完美,如下所示:
但是在另一个具有相同代码的屏幕中,我得到以下输出:
我无法理解问题出在哪里?这只发生在 iPad Only 。在 iphone 中,它运行良好。
我监视的另一件事是当我在两个屏幕上打印 cell.imageview 的大小时,我得到以下日志输出:
NSLog(@"Cell.imageview size W : %f H: %f",cell.imageView.frame.size.width,cell.imageView.frame.size.height);
它在屏幕 A 上给我输出如下:
Cell.imageview 尺码 W 88.000000 H: 88.000000
屏幕 B 如下:
Cell.imageview 详细尺寸 W : 44.000000 H: 44.000000
希望这个问题很好理解。
首先,如果您在 TableView 的委托方法中设置圆角半径,请不要这样做。
而不是 TableViewCell 的子类,并在其 AwakeFromNib 方法中设置圆角半径。这种方式更合适也更有效。
因为 CellForRowAtIndexPath 方法调用了单元格重新加载的次数。我们需要为每个单元格设置一次圆角。
请忽略任何格式,因为我在移动设备上 phone。
试试这个:
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return (minimun height of your cell);
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//SenderChatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SenderChatCell"];
return UITableViewAutomaticDimension;
}
这对我有帮助...希望对你也有帮助
我在 uitableview 中使用 UITableViewCell.imageView 来显示图像和图像视图的圆角。使用以下代码
[cell2.imageView setAutoresizingMask:UIViewAutoresizingNone];
cell2.imageView.backgroundColor = [UIColor whiteColor];
cell2.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell2.imageView.layer.masksToBounds = YES;
cell2.imageView.clipsToBounds = YES;
cell2.imageView.layer.borderWidth = 1.0f;
cell2.imageView.layer.borderColor = [UIColor colorWithRed:(1/255.0) green:(146/255.0) blue:(219/255.0) alpha:1.0].CGColor;
[cell2.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[ReviewArrayMain objectAtIndex:indexPath.row] valueForKey:@"logo"]]] placeholderImage:[UIImage imageNamed:@"Defaultlogo.png"] options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (error) {
NSLog(@"Error : %@", error);
}else{
cell2.imageView.image = image;
[cell2 layoutSubviews];
cell2.imageView.layer.cornerRadius = cell2.imageView.frame.size.height/2;
}
}];
我在一个屏幕上的输出越来越完美,如下所示:
但是在另一个具有相同代码的屏幕中,我得到以下输出:
我无法理解问题出在哪里?这只发生在 iPad Only 。在 iphone 中,它运行良好。
我监视的另一件事是当我在两个屏幕上打印 cell.imageview 的大小时,我得到以下日志输出:
NSLog(@"Cell.imageview size W : %f H: %f",cell.imageView.frame.size.width,cell.imageView.frame.size.height);
它在屏幕 A 上给我输出如下: Cell.imageview 尺码 W 88.000000 H: 88.000000
屏幕 B 如下: Cell.imageview 详细尺寸 W : 44.000000 H: 44.000000
希望这个问题很好理解。
首先,如果您在 TableView 的委托方法中设置圆角半径,请不要这样做。 而不是 TableViewCell 的子类,并在其 AwakeFromNib 方法中设置圆角半径。这种方式更合适也更有效。
因为 CellForRowAtIndexPath 方法调用了单元格重新加载的次数。我们需要为每个单元格设置一次圆角。
请忽略任何格式,因为我在移动设备上 phone。
试试这个:
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return (minimun height of your cell);
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//SenderChatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SenderChatCell"];
return UITableViewAutomaticDimension;
}
这对我有帮助...希望对你也有帮助