Question

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 !

Était-ce utile?

La solution 2

theButton.titleLabel.alpha = 0;

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top