theButton.titleLabel.alpha = 0;
How to set an invisible title on UIButton?
-
28-06-2022 - |
質問
I'm working on an Ipad application, and i need to set a title on a 'UIButton', in order to could use :
-(void)MyMethod:(id)sender
{
UIButton *resultButton = (UIButton *)sender;
if ([resultButton.currentTitle isEqualToString:@"TitleName"])
{
...
}
}
But when I use this sort of code :
[MyUibutton setTitle:@"TitleName" forState:UIControlStateNormal];
It appears "TitleName" behind the image of the 'UIButton'...
So, is it possible to fix it ?
Thanks !
解決 2
他のヒント
Don't use the button title, it's for display, not a flag. Instead use a tag
or objc_setAssociatedObject
Or store the button in a dictionary and compare.
If you set the image of the button, it will be at the top of the button, so the button's title won't be visible. Set the button's background and it will solve your problem !
[yourbutton setBackgroundImage:YOURIMAGE forState:UIControlStateNormal];
You can do [button setTitle:title forState:UIControlStateDisabled];
as long as you know you are not ever going to disable the button. Other than that, using the tag
property is probably the easiest.