Ios UIImageView';UITableviewCell中的内部内容大小
我有一个带有Imageview的Tableview单元格。 我想以全尺寸显示图像,即图像高度与实际图像相同 Tableview单元格高度应与实际图像高度相同 我如何才能做到这一点?Ios UIImageView';UITableviewCell中的内部内容大小,ios,iphone,xcode,imageview,tableview,Ios,Iphone,Xcode,Imageview,Tableview,我有一个带有Imageview的Tableview单元格。 我想以全尺寸显示图像,即图像高度与实际图像相同 Tableview单元格高度应与实际图像高度相同 我如何才能做到这一点? 谢谢,我假定您有一个具有图像名称的数组 使用以下方法 对于目标-C - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ UIImage *image
谢谢,我假定您有一个具有图像名称的数组 使用以下方法 对于目标-C
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UIImage *image = [UIImage imageNamed:[self.arrImages objectAtIndex:indexPath.row]];
if (image == nil){
return 36; //return any static value
} else {
return image.size.height;
}
}
用于Swift
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let image = UIImage(named: arrImages[indexPath.row])
image?.size.height
if image == nil {
return 36 //return any static value
} else {
return (image?.size.height)!
}
}
我假设您有一个具有图像名称的数组 使用以下方法 对于目标-C
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UIImage *image = [UIImage imageNamed:[self.arrImages objectAtIndex:indexPath.row]];
if (image == nil){
return 36; //return any static value
} else {
return image.size.height;
}
}
用于Swift
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let image = UIImage(named: arrImages[indexPath.row])
image?.size.height
if image == nil {
return 36 //return any static value
} else {
return (image?.size.height)!
}
}
我使用的代码与我使用的代码相同,对我有效。请确保您使用的是自动调整大小,而不是自动布局或大小类。使用此代码后,请告诉我问题所在?我使用的代码与我使用的代码相同,对我有效。请确保您使用的是自动调整大小,而不是自动布局或大小类。使用后请告诉我问题所在这