iOS 在 uitableview 单元格中设置图像宽度

标签 ios swift uitableview

我不确定为什么我的图像在我的 tableview 单元格中的宽度不相同

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{    
if (self.mySearchController.active)
    {

cell.imageView?.contentMode = UIViewContentMode.ScaleAspectFill
cell.imageView?.frame = CGRectMake(40, 60, 60, 24)
cell.imageView?.image = decodedimage
cell.imageView?.clipsToBounds = true
return cell
}}

输出:

enter image description here

如何在将所有图像设置到我的单元格之前使其具有固定宽度

最佳答案

UITableViewCell.imageView 将调整图像大小以适合单元格高度。如果你想有一个固定的宽度,你可以试试这个:

image = [UIImage imageWithCGImage:decodedimage.CGImage 
                            scale:fixedWidth / decodedimage.width
                      orientation:decodedimage.imageOrientation];

关于iOS 在 uitableview 单元格中设置图像宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835540/

相关文章:

iOS 表格标题和单元格之间的快速边距

IOS UITableViewCells 都混杂在第一个单元格中,尽管只有 Iphone5S 设备,64 位模拟器

objective-c - UINavigationController navigationBarHidden

ios - 创建 View Controller

ios - 尝试将来自 Web API 的照片添加到表中的各个行

ios - 同时解析 UITapGestureRecognizer 和 UILongPressGestureRecognizer 并在手指按下时触发 UIGestureRecognizer.State.began

swift - 使用动画设置 WKInterfacePicker 高度选择任意项目

ios - 如何在横向 View Controller 中快速显示网页 View ?

ios - UILabel 无法成为第一响应者并在 UITableView 中显示 inputView

ios - 无法通过 nsdictionary 中的键访问值