[英]image does not fit in the image view
我在swift做一个项目有一个图像视图,当我在图像视图中设置图像时,我从图库中获取图像,图像与图像视图的宽度和高度不匹配。 超时图像宽度和高度小于图像视图这里是代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "ImageTVCell"
index=indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? ImageTVCell
// cell?.imageView?.clipsToBounds=true
cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFit
cell?.imageView?.image=imageArray[indexPath.row]
return cell!
}
使用.aspectfill
并将clipsToBounds
设置为true
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "ImageTVCell"
index=indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? ImageTVCell
cell?.imageView?.clipsToBounds=true
cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFill
cell?.imageView?.image=imageArray[indexPath.row]
return cell!
}
cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFit
您的代码中的图像大小适合您的imageview。 你应该用,
cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFill
还使clipsToBounds = true。
要更好地了解Imageview内容模式,请访问http://blogs.innovationm.com/image-handling-in-ios/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.