Updated 31 May 2021
UITabBarController is one of the most commonly used UI elements of iPhone apps. It appears at the bottom of an app screen and provides the ability to switch between different sections of an app quickly. the TabBar controller is not very customizable and recommends only 5 icons before having to present a âmore optionsâ icon. A tab bar is often used to switch between different, but comparable view controllers.
Let’s create a project of the custom Tab bar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import UIKit class ViewController: UIViewController { @IBOutlet weak var TabBarView: UIView! @IBOutlet weak var Contentview: UIView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. TabBar() } func TabBar(){ TabBarView.layer.cornerRadius = TabBarView.frame.size.height/2 TabBarView.clipsToBounds = true } @IBAction func AllbuttonAction(_ sender: Any) { let tag = (sender as AnyObject).tag if tag == 0{ guard let home = self.storyboard?.instantiateViewController(identifier: "HomeViewController") as? HomeViewController else { return} Contentview.addSubview(home.view) home.didMove(toParent: self) }else if tag == 1{ guard let search = self.storyboard?.instantiateViewController(identifier: "SearchViewController") as? SearchViewController else { return} Contentview.addSubview(search.view) search.didMove(toParent: self) }else if tag == 2{ guard let camera = self.storyboard?.instantiateViewController(identifier: "CameraViewController") as? CameraViewController else { return} Contentview.addSubview(camera.view) camera.didMove(toParent: self) }else{ guard let profile = self.storyboard?.instantiateViewController(identifier: "ProfileViewController") as? ProfileViewController else { return} Contentview.addSubview(profile.view) profile.didMove(toParent: self) } } } |
Note:- If you don’t call it the child view controller won’t be able to detect that it did move to the parent view controller.
6. Now, run the project.
For other blogs Please click here
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
1 comments