Change the color of selected segment control

后端 未结 4 401
离开以前
离开以前 2021-01-02 23:18

In my app,i able to change the color of the selected segment control.But the color is changed for another index rather than selected index. I can find any mistake in the ind

4条回答
  •  失恋的感觉
    2021-01-02 23:40

    check out this one

    -(IBAction)segmentBtnPressed:(UISegmentedControl*)sender{
    for (int i=0; i<[sender.subviews count]; i++) 
    {
        if ([[sender.subviews objectAtIndex:i]isSelected] ) 
        {               
        UIColor *tintcolor=[UIColor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 alpha:1.0];
        [[sender.subviews objectAtIndex:i] setTintColor:tintcolor];
        }
        else{
         UIColor *tintcolor=[UIColor colorWithRed:127.0/255.0 green:161.0/255.0 blue:183.0/255.0 alpha:1.0];
        [[sender.subviews objectAtIndex:i] setTintColor:tintcolor];
    
        }
    }
    }
    

    Also you can check out more answers here UISegmentedControl selected segment color

提交回复
热议问题