How to set the buttons label text color for state UIControlStateHighlighted

前端 未结 3 542
日久生厌
日久生厌 2021-01-12 07:01

I am creating an iPhone application in which i have a custom button. i have set the buttons title by creating a Label and adding it as subview. now when the button is highli

相关标签:
3条回答
  • 2021-01-12 07:25

    Found the answer in a different question on StackOverflow: UIButton color issues

    [button1 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    

    This is if you can work without creating a Label and adding it as subview as you mention above.

    0 讨论(0)
  • 2021-01-12 07:30

    For SelectedColor

    [yourButton setTitleColor:[UIColor purpleColor] forState:UIControlStateSelected];
    

    For HighlightedColor

    [yourButton setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    
    0 讨论(0)
  • 2021-01-12 07:35

    you can add target for UIControlStateHighlighted state of UIButton like

    [button1 addTarget:self action:@selector(buttonHighlighted:) forControlEvents:UIControlStateHighlighted];
    

    and in buttonHighlighted method you can change the color of your label's text

    - (void) buttonHighlighted:(id)sender
    {
      //code here
    }
    

    Hope it gives you an idea.

    0 讨论(0)
提交回复
热议问题