Created
September 30, 2016 06:08
-
-
Save EQuimper/75cfbd4606a5b8e042f99c1e3a55597b to your computer and use it in GitHub Desktop.
This is a snippet for make a tinder lookALike swiping with image showing to the side
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
import UIKit | |
class ViewController: UIViewController { | |
var images = [UIImageView]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
// For get the width of the view | |
override func viewDidAppear(_ animated: Bool) { | |
var contentWidth: CGFloat = 0.0 | |
print("Scrollview width: \(scrollView.frame.size.width)") | |
let scrollWidth = scrollView.frame.size.width | |
for x in 0...2 { | |
let image = UIImage(named: "icon\(x).png") | |
let imageView = UIImageView(image: image) | |
images.append(imageView) | |
var newX: CGFloat = 0.0 | |
newX = scrollWidth / 2 + scrollWidth * CGFloat(x) | |
contentWidth += newX | |
scrollView.addSubview(imageView) | |
// For center the image | |
imageView.frame = CGRect(x: newX - 75, y: (scrollView.frame.size.height / 2) - 75, width: 150, height: 150) | |
} | |
// For getting image a bit in the side | |
scrollView.clipsToBounds = false | |
scrollView.contentSize = CGSize(width: contentWidth, height: view.frame.size.height) | |
} | |
@IBOutlet weak var scrollView: UIScrollView! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment