图像滚动但是,它们不会缩放以适合滚动视图。我尝试添加
imageView.contentMode = .scaleAspectFit
但这只是让它变得更小。
这就是我的意思:
class DonateViewController: UIViewController {
@IBOutlet weak var mainscrollView: UIScrollView!
var imageArray = [UIImage]()
@IBOutlet weak var tableView: UITableView!
var model: [DonationFund]!
override func viewDidLoad() {
super.viewDidLoad()
imageArray = [#imageLiteral(resourceName: "333"),#imageLiteral(resourceName: "111"),#imageLiteral(resourceName: "222")]
for i in 0..<imageArray.count{
let imageView = UIImageView()
imageView.image = imageArray[i]
imageView.contentMode = .scaleAspectFit
let xPosition = self.view.frame.width * CGFloat(i)
imageView.frame = CGRect(x: xPosition, y: 0, width: self.mainscrollView.frame.width, height: self.mainscrollView.frame.height)
mainscrollView.contentSize.width = mainscrollView.frame.width * CGFloat(i + 1)
mainscrollView.addSubview(imageView)
}