'ScrollView not covering entire screen in XCode
I'm running into an issue that has me rather puzzled. I have a UIView in Xcode with a ScrollView inside of it. I also have a UIView inside the ScrollView that I would like to cover the entire width of the device screen currently running the app.I have the ScrollView pinned to the outer UIView with the trailing constraint = 0
, and when I test programmatically I find that the inner UIView.frame.width ScrollView.frame.width = UIScreen.frame.bounds.width
. However, when I set the background color of the inner UIView, about 3 pixels on the right hand side do not get colored.
I've posted code and images below. You can see the space to the right of the bar at the bottom of the screen
var bar: UIView
bar = UIView(frame: CGRectMake(0, (ScrollView.frame.size.height + 10), UIScreen.mainScreen().bounds.width, 75))
bar.backgroundColor = UIColor.blueColor()
ScrollView.addSubview(bar)
ScrollView.contentSize.height = ScrollView.frame.size.height + 85
UPDATE:
I found this blog post that says ScrollView should only have one subview. I'm checking into it now.
Solution 1:[1]
Thanks to Phillip Mills, who pointed me in the right direction for solving my problem. It turns out the frame of my ScrollView was set with a minX value of -4, and it shifted the entire ScrollView over, creating the space at the right of the screen. I'm not entirely sure how it got there, but once I fixed this everything worked the way I wanted it to.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |