Skip to content

Instantly share code, notes, and snippets.

@kobeumut
Created April 1, 2018 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobeumut/ec0ab133bb89b41d88b0a518efcbd9b6 to your computer and use it in GitHub Desktop.
Save kobeumut/ec0ab133bb89b41d88b0a518efcbd9b6 to your computer and use it in GitHub Desktop.
//
// AdDetailVC.swift
//
//
// Created by GriSoft Mobile on 31.03.2018.
// Copyright © 2018 All rights reserved.
//
import UIKit
class AdDetailVC: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var adImageSliderScrollView: UIScrollView!
@IBOutlet weak var imagePageControl: UIPageControl!
var i = 0
var featureArray = [UIImage(named: "55")!, UIImage(named: "56")!, UIImage(named: "57")!]
override func viewDidLoad() {
super.viewDidLoad()
adImageSliderScrollView.delegate = self
adImageSliderScrollView.contentSize = CGSize(width: adImageSliderScrollView.frame.width * CGFloat(featureArray.count), height: adImageSliderScrollView.frame.height)
for i in 0..<featureArray.count{
let imageview = UIImageView()
imageview.image = featureArray[i]
imageview.contentMode = .scaleAspectFill
imageview.clipsToBounds = true
let xPosition = self.adImageSliderScrollView.frame.width * CGFloat(i)
imageview.frame = CGRect(x: xPosition, y: 0, width: self.adImageSliderScrollView.frame.width, height: self.adImageSliderScrollView.frame.height)
print(imageview)
adImageSliderScrollView.addSubview(imageview)
}
// let scrollingTimer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(self.newStartScrolling), userInfo: nil, repeats: true)
// scrollingTimer.fire()
}
@objc func newStartScrolling()
{
if i == featureArray.count {
i = 0
}
let x = CGFloat(i) * adImageSliderScrollView.frame.size.width
adImageSliderScrollView.setContentOffset(CGPoint(x: x, y: 0), animated: true)
self.i += 1
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let page = scrollView.contentOffset.x / scrollView.frame.size.width
imagePageControl.currentPage = Int(page)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment