UIScrollView:缩放以适应屏幕宽度

时间:2016-04-08 11:53:00

标签: ios swift 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)

你能吗?

1 个答案:

答案 0 :(得分:0)

myImageView = UIImageView(image: UIImage(named: "image.png"))
myImageView.frame = view.bounds
myImageView.contentMode = .ScaleAspectFill
view.addSubview(myImageView)