Search code examples
iosobjective-cuibutton

How to disable UIButton highlight on click?


How to disable button highlight effect on click? Have custom button with white bg color and DarkGray text color. The problem is the text becomes white on button click. Already tried but none of them worked:

a. Did uncheck "Highlighted Ajusts Image" in interface builder.

b. Tried setting highlighted = NO in button pressed method:

((UIButton *)sender).highlighted = NO

c. Tried setting the same title for highlihted state:

[button setTitle:[button titleForState:UIControlStateNormal] forState:UIControlStateHighlighted];

Any suggestions?


Solution

  • UIButton will highlighted on click, so check button setting Change the title color in highlight state config to same as default state Or you can set:

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    

    If you want to control Highlighted by code, you can disable normal highlighted by subclass Button and disable in touchesBegin:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        if (self.state == UIControlStateHighlighted) {
            [self setHighlighted:NO];
        }
    }