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

theButton.titleLabel.alpha = 0;

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top