Search code examples
iphoneiosios4

How to use three buttons as like segment control


enter image description hereHi may anyone let me know how to use three buttons to use like segment control in iPhone.


Solution

  • Set tag on each button.

    [button1 setTag:0];
    [button2 setTag:1];
    [button3 setTag:2];
    

    Then put the same @selector method for all buttons.

    Then in your button selector method do this:-

     -(IBAction)youButtonMethod:(id)sender
    {
        if([sender tag] == 0)
        {
           // your first button click
        }
    
        else if([sender tag] == 1)
        {
           // your second button click
        }
    
        else if([sender tag] == 2)
        {
           // your third button click
        }
    }