Updated 24 January 2024
Suppose you want to add a floating button in iOS. Firstly, you have to create a UIButton or UIView and add that button or view in the UIWindow of your application and you can also move thatĀ button when you are leaving the UIViewController. Call the method viewWillDisappear and remove your view from the current view. Example :-
1 2 3 4 5 6 7 8 |
// Add your Button var saveButton = UIView() self.saveButton = UIView(frame: CGRect(x: SCREEN_WIDTH - 80 , y: height - 130, width: 60, height: 60)) self.saveButton.backgroundColor = UIColor().HexToColor(hexString: accent_color) self.saveButton.layer.cornerRadius = (self.saveButton.frame.size.height) / 2 self.saveButton.layer.masksToBounds = true; self.saveButton.isUserInteractionEnabled = true UIApplication.shared.keyWindow?.addSubview(self.saveButton) |
Remove from view :-
1 2 3 |
override func viewWillDisappear(_ animated: Bool) { self.saveButton.removeFromSuperview() } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.