Chris_1983_Norway
Chris_1983_Norway

Reputation: 399

What is the best way to create a tab view within a ViewController

I'm trying to create a design where a section of the ViewController has three buttons that show different content depending on what button is selected. Basically UITabBarController but within a viewcontroller

Design

Basically the deer, fish and the bird icons will be buttons, showing different content in an imageView below. Is there a built in function in Xcode that you recommend for this? Or should I create three buttons, showing/hiding the relevant UIViews? What is the most efficient?

Upvotes: 0

Views: 41

Answers (1)

Terje
Terje

Reputation: 1000

Your image isn't showing up but could a Segmented Control be what you are after? enter image description here

Hook its Value Changed up to an action in your View Controller and respond to which item is selected by showing/hiding different views for example:

@IBAction func controlChanged(_ sender: Any) {
    guard let segmentedControl = sender as? UISegmentedControl else { return }

    let activeViewIndex = segmentedControl.selectedSegmentIndex
    // Show the view based on activeViewIndex here
}

Upvotes: 1

Related Questions