Skip to content

Instantly share code, notes, and snippets.

@traviskirton
Created April 9, 2016 16:17
Show Gist options
  • Select an option

  • Save traviskirton/ee9c5daedcd71e244dfcea099cfbdb51 to your computer and use it in GitHub Desktop.

Select an option

Save traviskirton/ee9c5daedcd71e244dfcea099cfbdb51 to your computer and use it in GitHub Desktop.
Half the Scrollview
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