The image below is a picture of a view with two uibarbuttons and a segmented control. The salesforce button when reached redirects the user to a website.How can I change the salesforce button to a different button when the third index of the segment control is reached ? This second button is meant to display a new view controller.
2
Answers
I think it would be easier to change the appearance and the button behaviour instead of changing the button itself.
Sadly you didn´t provide any context if this view is from a storyboard or created by code. In my answer I´m assuming it´s from storyboard.
Create an outlet for you button:
From your
UISegmentedControl
in storyboard create anIBAction
in your viewcontroller. That action should look something like this.Then create that function:
If no
IBAction
is defined for yourmyButton
you would need to call theconfigureButton
function from yourviewDidLoad
function.Firstly get the index of the selected segment using,
.selectedSegemtIndex
property.Then, check the condition stating that, if the index is equals your target segment index, define statements to change the title, background color, or even the action of the button if required.