我在表格视图单元格中使用带有图像的滚动视图但是有两个问题:1-有一个额外的页面不是我的图像数量和2:图像没有填满屏幕并且每个图像之间都有空白
这是我的带有滚动视图代码的表格视图单元格
class scrollViewCell: UITableViewCell , UIScrollViewDelegate {
@IBOutlet weak var pageControl: UIPageControl!
@IBOutlet weak var scrollView: UIScrollView!
var contentWidth : CGFloat = 0.0
override func awakeFromNib() {
super.awakeFromNib()
scrollView.delegate = self
for image in 0...2 {
let imageToDisplay = UIImage(named : "1")
let imageView = UIImageView(image : imageToDisplay)
let xCoordinate = self.contentView.frame.midX + self.contentView.frame.width * CGFloat(image)
contentWidth += self.contentView.frame.width
scrollView.addSubview(imageView)
imageView.frame = CGRect(x: xCoordinate - 50 , y: 0 , width: self.contentView.frame.width, height: 100)
imageView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleBottomMargin, .flexibleRightMargin, .flexibleLeftMargin, .flexibleTopMargin]
imageView.contentMode = .scaleAspectFit // OR .scaleAspectFill
imageView.clipsToBounds = true
}
scrollView.contentSize = CGSize(width: contentWidth, height: self.contentView.frame.height)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
pageControl.currentPage = Int(scrollView.contentOffset.x / CGFloat(414))
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}