I have a scrollview of an array of images, it works for the images to scroll left and right but I cannot scroll down, instead I am able to scroll my tableview cells...I need to be able to scroll downwards and not have my array of images fixed on the view, is there any ways?
the codes i used are :
override func viewDidLoad() {
super.viewDidLoad()
scrollView.frame = view.frame
imageArray = [UIImage(named:"adsImage3")!,UIImage(named:"adsImage2")!,UIImage(named:"adsImage")!]
navigationController?.navigationBar.barTintColor = UIColor.white
for i in 0..<imageArray.count {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
imageView.image = imageArray[i]
let xPosition = self.view.frame.width * CGFloat(i)
imageView.frame = CGRect(x: xPosition, y: 0, width: self.scrollView.frame.width, height: 380)
scrollView.contentSize.width = scrollView.frame.width * CGFloat(i + 1)
scrollView.addSubview(imageView)
}
}
as for my storyboard, it looks like:
if I were to put my scrollview in my tableview, my code would be func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: MainMenuRowSelectionTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MainMenuRowSelectionTableViewCell
var cellColors = ["#FFB3B3","#FFFFFF"]
cell.contentView.backgroundColor = UIColor(hexString: cellColors[indexPath.row % cellColors.count])
imageArray = [UIImage(named:"adsImage3")!,UIImage(named:"adsImage2")!,UIImage(named:"adsImage")!]
for i in 0..<imageArray.count {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
imageView.image = imageArray[i]
}
return cell
}
and my storyboard
this way,my scroll view wouldnt appear at all