今天想要實作 scrollView
記得先準備一張解析度大於1920 * 1080 的照片 (named:”image.jpg”)
class ViewController: UIViewController {
var myScrollView : UIScrollView!
var fullSize : CGSize!
var myImageView : UIImageView!
//get the screen size
fullSize = UIScreen.main.bounds.size
//add a image form file
myImageView = UIImageView(image: UIImage(named: "image.jpg"))
myScrollView = UIScrollView()
myScrollView.contentSize = myImageView.bounds.size
myScrollView.backgroundColor = UIColor.black
myScrollView.frame = CGRect(x: 0, y: 0, width: fullSize.width, height: fullSize.height)
myScrollView.contentOffset = CGPoint(x:(myImageView.center.x - (myScrollView.frame.width / 2 ) + 300), y:(myImageView.center.y - (myScrollView.frame.height / 2) + 500))
//set up the idicator of scrollview
myScrollView.indicatorStyle = .white
myScrollView.showsHorizontalScrollIndicator = true
myScrollView.showsVerticalScrollIndicator = true
myScrollView.addSubview(myImageView)
self.view.addSubview(myScrollView)