0

I have read the manual (https://material.io/develop/ios/components/buttons/), but still have not understood how to do it.

class FloatingButtonController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let floatingButton = MDCFloatingButton()
    floatingButton.setImage( UIImage(named: "plus"), for: .normal)
    floatingButton.backgroundColor = .white
    floatingButton.setElevation(ShadowElevation(rawValue: 6), for: .normal)
    floatingButton.addTarget(self, action: #selector(btnFloatingButtonTapped(floatingButton:)), for: .touchUpInside)
    self.view.addSubview(floatingButton)
}

@objc func btnFloatingButtonTapped(floatingButton: MDCFloatingButton){
    floatingButton.collapse(true) {
        floatingButton.expand(true, completion: nil)
    }
}
}

My project on the screen. As you can see - the button is missing on the screen. When you click on a blank screen errors appear.

Button touch target does not meet minimum size guidlines of (48, 48). Button: >, Touch Target: {0, 0}

Screenshot of my project

Tell me, please, what am I doing wrong? And how do I get the job right?

4
  • see this post material.io/develop/ios/components/buttons Commented Feb 27, 2019 at 10:01
  • try using initWithFrame: method instead of MDCFloatingButton() Commented Feb 27, 2019 at 10:02
  • you forget to add the frame for your button Commented Feb 27, 2019 at 10:02
  • @Akhilrajtr , I used the Mahendra answer and it worked. But I would be curious to know more about what you are offering. I am a junior in Swift, could you give a more detailed example? Commented Feb 27, 2019 at 10:29

2 Answers 2

2

You didn't set the frame to button. You need to specify (x, y) position to place button in view.

floatingButton.frame = CGRect(x: 300, y: 300, width: 48, height: 48)
Sign up to request clarification or add additional context in comments.

Comments

0

To add button target the button should have size atlease 48x48.

You could constraint it manually or set frame.

OR you could add button via Storyboard too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.