UIButton does not diplay text set with [UIButtonname setTitle]
For the following code (where the UIButton is not connected to an IBOutlet):
UIImage *defaultButton = [UIImage imageNamed:@"StandardButton.png"];
PlayButton = [[UIButton alloc] initWithFrame:CGRectMake(250, 50, 220, 50)];
[PlayButton setImage:defaultButton forState:UIControlStateNormal];
[Play开发者_运维知识库Button setTitle:@"PlayButton" forState:UIControlStateNormal];
[PlayButton addTarget:self action:@selector(StoryModeReleased:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:PlayButton];
The PlayButton pointer is declared in the .h file. The button text does not appear when I use this code, but the button displays whith the image. How can I make the text display?
Try this :
PlayButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *defaultButton = [UIImage imageNamed:@"StandardButton.png"];
PlayButton.frame = CGRectMake(250, 50, 220, 50)];
[PlayButton setImage:defaultButton forState:UIControlStateNormal];
[PlayButton setTitle:@"PlayButton" forState:UIControlStateNormal];
[PlayButton addTarget:self action:@selector(StoryModeReleased:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:PlayButton];
I think you forgot about declare the type of the button
精彩评论