Why does my UIButton.titleLabel.text disappear when I put an image in a button?

I had this problem before, but I managed to get around this so far. Basically, I create a UIbutton user interface, setting its image as uiimage, and then the button that had the label on until I applied the code below it loses its label. I need this label because it is set programmatically in the following code.

 NSString *imageName = [NSString stringWithFormat:kNameOfButtonimage ];
            UIImage *image = [UIImage imageNamed:imageName];
            [button setImage:image forState:UIControlStateNormal ];

Any help you could provide would be greatly appreciated.

-nick

+3
source share
1 answer

I needed to do:

[button setBackroundImage:image forState:UIControlStateNormal ];

instead of this:

[button setImage:image forState:UIControlStateNormal ];

;)

+5
source

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


All Articles