How to set the buttons label text color for state UIControlStateHighlighted

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 highlighted i want to change the labels text color.

here is my code,

  • iOS: Open a Calendar app New Event screen with populated date
  • In App Purchase
  • Send mail without MFMailComposeViewController
  • Is there a public API for card view UI that can be seen across iOS 10?
  • How does an 'annot' CGPDFDictionary 'Rect' translate to objective c Rect
  • Execute an “if” condition “x” milliseconds and stop for “y”millisecond and repeat the condition ?
  • UIButton *button1= [UIButton buttonWithType:UIButtonTypeCustom];
        [button1 setFrame:CGRectMake(68,162, 635, 101)];    
        [button1 setImage:[UIImage imageNamed:@"startwithouttext.png"] forState:UIControlStateNormal];
        [button1 setImage:[UIImage imageNamed:@"startactivewithouttext.png"] forState:UIControlStateHighlighted];
       UILabel *buttonLabel = [[UILabel alloc]  initWithFrame:CGRectMake(button1.bounds.origin.x+50, button1.bounds.origin.y+20, button1.bounds.size.width-100, button1.bounds.size.height-40)];
        [buttonLabel setFont:[UIFont fontWithName:@"Helvetica" size:28]];
        buttonLabel.backgroundColor=[UIColor clearColor];
        buttonLabel.textColor=[UIColor colorWithRed:83.0/255.0 green:83.0/255.0 blue:83.0/255.0 alpha:1.0];
        buttonLabel.highlightedTextColor=[UIColor whiteColor];
        buttonLabel.text = @"Long text string";
        [button1 addSubview:buttonLabel];
        [button1 bringSubviewToFront:buttonLabel];
        [button1 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
        [button1 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        [button1 addTarget:self action:@selector(button1clicked:) forControlEvents:
    [mainView button1];   

    can any body help me to change the text color when the button is highlighted?

    3 Solutions Collect From Internet About “How to set the buttons label text color for state UIControlStateHighlighted”

    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.

    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.

    For SelectedColor

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

    For HighlightedColor

    [yourButton setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];