I'm a pretty newbie in (swift) programming so I hope you can forgive me if I phrase or ask something stupid.
I have a ViewController
with a ScrollView
. I fill the ScrollView
with different content, like a TableView
and ImageViews. Next, I would like to add a button. This button should be in the lower right corner of the display, no matter where the user scrolls down or up. Can you give me some guidance? Basically, I'm looking for a property that will allow me to reference the edge of the display.
well, friend you have to set your button outside scrollView layer .
you can do this in Canvas(storyboard or xib file) make sure its above scrollView layer
the easy way adde with code like this:
let screenHeight = UIScreen.main.bounds.height
let buttonHeight:CGFloat = 45.0
let screenWidth = UIScreen.main.bounds.width
let buttonWidth:CGFloat = 200.0
let padding:CGFloat = 30.0
let customframe = CGRect(x:(screenWidth - buttonWidth - padding) , y: (screenHeight - buttonHeight - padding), width: buttonWidth, height: buttonHeight)
let floatingButton = UIButton(frame: customframe)
floatingButton.backgroundColor = .blue
self.view.addSubview(floatingButton)
self.view.bringSubviewToFront(floatingButton)
make sure you add your button to self.view and call bringSubViewToFront after, this will to as it sounds but you have to add your layer first to do somthing.