我正在使用UICollectionView放置图像。
我想在以下条件下排列所有图像。
(就像ios filemanager)
1. AspectFit
2.底部对齐
3.具有转角半径
这是参考图像。
为了实现此目的,应使用imageView编写什么样的代码?
最佳答案
感谢大家。
我用一个非常简单的计算解决了这个问题。
//swift
/*
cW = UIImage's width
cH = UIImage's height
cS = UIViewImage's height or width(my case is square. so whichever is fine)
*/
func resizeImageView(cW w:CGFloat, cH h:CGFloat, cS s:CGFloat) -> (a:CGFloat, b:CGFloat) {
if w > h{
let a = (h * s) / w
let b = (s - a)
return (CGFloat(a), CGFloat(b))
}else{
let a = (w * s) / h
let b = (s - a) / 2.0000
return (CGFloat(a), CGFloat(b))
}
}
之后,使用每个值更改imageView的宽度,高度,x,y。
关于ios - ImageView作为AspectFit和BottomAlignment和CornerRadius,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48524217/