Swift - 滚动视图适合整个屏幕吗?

时间:2015-06-14 18:38:24

标签: ios xcode swift uiscrollview uiimageview

我的滚动视图不完全适合屏幕。顶部和左侧有黑色边框。它看起来像这样。enter image description here

以下是我用来创建scrollView的代码:

imageView = UIImageView(image: UIImage(named: "Map 1.png"))
scrollView = UIScrollView(frame: view.bounds)
scrollView.backgroundColor = UIColor.blackColor()
scrollView.contentSize = imageView.bounds.size
scrollView.addSubview(imageView)
view.addSubview(scrollView)

2 个答案:

答案 0 :(得分:0)

也许你会删除"调整滚动视图插图"来自UIViewController

enter image description here

答案 1 :(得分:-1)

imageView = UIImageView(image: UIImage(named: "Map 1.png"))
imageView.contentMode = .ScaleToFill       
imageView.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.width  , height: self.scrollView.frame.height)

scrollView.contentSize.width = scrollView.frame.width       
scrollView.addSubview(imageView)

view.addSubview(scrollView)