ios - 如何让我的 Image 填满整个 ScrollView?

标签 ios swift uiscrollview uiimageview

我有一组图像,我想制作水平图像 slider 。但图像并不总是适合整个 ScrollView 。这是我的代码:

scrollView.delegate = self

scrollView.isPagingEnabled = true
scrollView.showsHorizontalScrollIndicator = false

for (index, imageView) in imagesArray.enumerated() {
    imageView.frame.size.height = scrollView.frame.size.height
    imageView.frame.size.width = scrollView.frame.size.width
    imageView.contentMode = .scaleAspectFill
    imageView.clipsToBounds = true
    scrollView.addSubview(imageView)
    imageView.frame.origin.x = CGFloat(index) * self.view.bounds.size.width
}
scrollView.contentSize.width = self.view.frame.width * CGFloat(imagesArray.count)

我希望图像填满下图中黑色边框区域内的整个区域。

enter image description here

最佳答案

我觉得你只需要修改一下行

imageView.contentMode = .scaleAspectFill

imageView.contentMode = .scaleAspectFit

关于ios - 如何让我的 Image 填满整个 ScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50317334/

相关文章:

ios - 为什么我得到 "Terminating app due to uncaught exception ' NSInvalidArgumentException',原因 : '-[UIImageView _isResizable]: unrecognized selector"

ios - 如何使 MKAnnotations 在 map 上平滑移动(调整其坐标)?

swift - Collection View 向下移动单元格

swift - 使用 Collection View 使 View Controller 可滚动

ios - UITableView 在滚动/分页时没有正确处理 contentOffset

ios - 错误 "Use of unresolved identifier ' EKEntityTypeEvent'“尝试访问日历

ios - JSON 字符串不会被解析

objective-c - 如何让 imageview 做一个 segue

swift - 如何在 Vapor 3 中进行第三方 api 调用?

ios - 如何使用 contentOffset 使 UIScrollView 中的内容居中