Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button titleLabel set to hidden YES, reappears on touch

In a view controller I have set up the following code to initially hide a button array group:

- (void)viewDidLoad {
    [super viewDidLoad];
    for(UIButton * noteButtonItem in noteButtonArray){
        noteButtonItem.titleLabel.hidden = YES;
        //NSLog(@"Title is %@", noteButtonItem.currentTitle);
    }
}

From the .h file:

@property (nonatomic,retain) IBOutletCollection(UIButton) NSArray *noteButtonArray;

And attached via IB

The initial hide works fine, but when ever I "touch" a button (in the simulator), the titleLabel doesn't stay hidden.

What is going on behind the scenes? Is there a way to make them stay hidden until hidden is set to YES?

like image 868
jmhead Avatar asked Dec 28 '22 08:12

jmhead


1 Answers

UIButton instances can have different configurations depending on their state (states described here). If you want to hide the button's title label in all states, you could make use of setTitle:forState: and set its title to @"", or you could change the alpha property of the color to 0.0f with setTitleColor:forState: so it becomes transparent when the button is in the states chosen.

like image 134
Fran Sevillano Avatar answered Jan 20 '23 18:01

Fran Sevillano