skip to Main Content

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.

Storyboard Screenshot

2

Answers


  1. I don’t know how you have your view (you could put your code, that would help the question more), on the contrary, what occurs to me in the way of integrating a button, is to use the JJFloatingActionButton pod and it allows you to have a floating button in your view.
    Visit https://cocoapods.org/pods/JJFloatingActionButton for more info about this library.

    Login or Signup to reply.
  2. 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.

    • no matter how many layers you have, or having scrollView. this will work on all and all iphone sizes
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search