Last active
January 31, 2019 13:06
-
-
Save filimo/b6b12022646d77ad94b4572308c9f7c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// UIScrollView | |
// | |
// Created by VKushnerov on 1/31/19. | |
// Copyright © 2019 VKushnerov. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController, UIScrollViewDelegate { | |
var myScrollView = UIScrollView() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let scrollViewRect = view.bounds | |
myScrollView = UIScrollView(frame: scrollViewRect) | |
myScrollView.isPagingEnabled = true | |
myScrollView.contentSize = CGSize(width: scrollViewRect.size.width * 3, height: scrollViewRect.size.height) | |
view.addSubview(myScrollView) | |
let images = ["iphone", "ipad", "macbook"] | |
for imageName in images { | |
addNewImageView(imageName: imageName) | |
} | |
} | |
func addNewImageView(imageName: String) { | |
var imageViewRect = view.bounds | |
let image = UIImage(named: imageName) | |
imageViewRect.origin.x = imageViewRect.size.width * CGFloat(myScrollView.subviews.count) | |
let imageView = newImageViewWithImage(paramImage: image!, paramFrame: imageViewRect) | |
myScrollView.addSubview(imageView) | |
} | |
func newImageViewWithImage(paramImage: UIImage, paramFrame: CGRect) -> UIImageView { | |
let result = UIImageView(frame: paramFrame) | |
result.contentMode = .scaleAspectFit | |
result.image = paramImage | |
return result | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment