The titleLabel button is set to hidden YES, appears again when touched

In the view controller, I installed the following code to initially hide a group of button arrays:

- (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 original hide works fine, but when I “touch” the button (in the simulator), the title does not remain hidden.

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

+4
source share
2 answers

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

+10
source

You can use one of the tracking methods to make sure that it remains hidden even after it is “touched”. This is from the UIControl class reference:

Track contacts and redraw controls

  • - beginTrackingWithTouch: withEvent:
  • - continueTrackingWithTouch: withEvent:
  • - endTrackingWithTouch: withEvent:
  • - cancelTrackingWithEvent:
  • tracking property
  • touchInside property
0
source

Source: https://habr.com/ru/post/1388069/


All Articles