banner



How To Programmatically Add A Segmented Controller Swift

How to programmatically add a UISegmentedControl to a container view?


To add together a UISegmentControl in iOS with swift we'll have to offset create a segment control and it's controller function, i.due east. it'south action. Let's see those steps.

Let's create a function to add together a segmented command.

func addControl() {    let segmentItems = ["Showtime", "Second"]    let command = UISegmentedControl(items: segmentItems)    command.frame = CGRect(x: x, y: 250, width: (self.view.frame.width - 20), peak: fifty)    control.addTarget(self, activeness: #selector(segmentControl(_:)), for: .valueChanged)    control.selectedSegmentIndex = 1    view.addSubview(command) }

This role may exist called in our view controller to add the segmented control, allow'southward add action for this control.

@objc func segmentControl(_ segmentedControl: UISegmentedControl) {    switch (segmentedControl.selectedSegmentIndex) {       case 0:          // First segment tapped       break       instance 1:          // 2nd segment tapped       break       default:       intermission    } }

When we run the same code on an iOS simulator below Is the output that'south produced.

raja

Published on 21-Jan-2019 12:xl:47

  • Related Questions & Answers
  • Add a heading container to Bootstrap console
  • How to add footer view to android listview?
  • How to add together a container for an external (non-HTML) application in HTML5
  • How to add custom view in alert dialog?
  • Disable Scroll View Programmatically in iOS?
  • How to add a border to the top and lesser of an iOS View?
  • How to add a border to the height and bottom of an Android View?
  • How to create a MySQL view?
  • How to backup and restore a Docker Container?
  • How to go a Docker Container IP address?
  • How to run a command inside Docker Container?
  • How to Dynamically Add Views into View in Android?
  • Grant a user permission to merely view a MySQL view?
  • How to edit a file after I shell to a Docker container?
  • How to programmatically take a screenshot in android?

How To Programmatically Add A Segmented Controller Swift,

Source: https://www.tutorialspoint.com/how-to-programmatically-add-a-uisegmentedcontrol-to-a-container-view

Posted by: murraycallather.blogspot.com

Related Posts

0 Response to "How To Programmatically Add A Segmented Controller Swift"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel