Custom UISegmentedControl

Discussion in 'iOS Programming' started by idelovski, Dec 30, 2010.

  1. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #1
    What is the point of image property in UISegmentedControl if standard look is drawn underneath my images so resulting control looks like a total mess?

    Is there any other way to do a custom drawn segmented control? Googling wasn't much help.
     
  2. nickculbertson macrumors regular

    nickculbertson

    Joined:
    Nov 19, 2010
    Location:
    Nashville, TN
    #2
    You could use UIButtons instead to get a custom look. For each "segment" you want, stack two buttons (one for highlighted and one not pressed) Then hide the buttons not selected.

    Code:
    - (IBAction)press1{
        //your action
        button1.hidden=YES;
        button1highlight.hidden=NO;
        button2.hidden=NO;
        button2highlight.hidden=YES;
    }
    - (IBAction)press1highlight{
        button1.hidden=NO;
        button1highlight.hidden=YES;
        button2.hidden=NO;
        button2highlight.hidden=YES;
    }
    - (IBAction)press2 {
        button1.hidden=NO;
        button1highlight.hidden=YES;
        button2.hidden=YES;
        button2highlight.hidden=NO;
    }
    - (IBAction)press2highlight{
        button1.hidden=NO;
        button1highlight.hidden=YES;
        button2.hidden=NO;
        button2highlight.hidden=YES;
    }
    
    
    -(void)viewDidLoad{
        button1.hidden=NO;
        button1highlight.hidden=YES;
        button2.hidden=NO;
        button2highlight.hidden=YES;
    }
    
    Nick
     
  3. idelovski thread starter macrumors regular

    Joined:
    Sep 11, 2008
    #3
    Thanks,

    I'll probably end up with something like that.
     

Share This Page