Created
April 9, 2016 16:17
-
-
Save traviskirton/ee9c5daedcd71e244dfcea099cfbdb51 to your computer and use it in GitHub Desktop.
Half the Scrollview
This file contains hidden or 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
| class ViewController: UIViewController, UIScrollViewDelegate { | |
| @IBOutlet var scrollView: UIScrollView? | |
| var elementSize = CGSizeZero | |
| var grid = (6, 8) | |
| var container: UIView? | |
| override func viewDidLoad() { | |
| scrollView?.delegate = self | |
| elementSize = UIImage(named: "chop")!.size | |
| container = UIView() | |
| container?.frame = CGRect(x: 0, | |
| y: 0, | |
| width: CGFloat(grid.0) * elementSize.width, | |
| height: CGFloat(grid.1) * elementSize.height) | |
| for x in 0..<grid.0 { | |
| for y in 0..<grid.1 { | |
| let filename = (x + y) % 2 == 0 ? "chop" : "rockies" | |
| let img = UIImage(named: filename) | |
| let imgv = UIImageView(image: img) | |
| let origin = CGPoint(x: CGFloat(x) * elementSize.width, | |
| y: CGFloat(y) * elementSize.height) | |
| imgv.frame = CGRect(origin: origin, size: elementSize) | |
| container?.addSubview(imgv) | |
| } | |
| } | |
| scrollView?.addSubview(container!) | |
| scrollView?.contentSize = container!.bounds.size | |
| scrollView?.minimumZoomScale = 0.1 | |
| scrollView?.maximumZoomScale = 6.0 | |
| scrollView?.indicatorStyle = UIScrollViewIndicatorStyle.White | |
| } | |
| func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? { | |
| return container | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment