2016-04-08 78 views
0

我努力使圖像適應屏幕寬度 - 一個UIScrollView內的圖像:
的UIScrollView:縮放以適應屏幕寬度

myImageView = UIImageView(image: UIImage(named: "image.png")) 
scrollView = UIScrollView(frame: view.bounds) 
let w = myImageView.bounds.width 
let h = myImageView.bounds.height 
let r = CGRect(x: 0, y: 0, width: w, height: h) 
scrollView.zoomToRect(r, animated: false) 
scrollView.delegate = self 

scrollView.addSubview(myImageView) 
view.addSubview(scrollView) 

可以嗎?

+0

你爲什麼不設置'UIImageView'的'contentMode'屬性 –

回答

0
myImageView = UIImageView(image: UIImage(named: "image.png")) 
myImageView.frame = view.bounds 
myImageView.contentMode = .ScaleAspectFill 
view.addSubview(myImageView) 
相關問題