1

我正在尝试在按钮上显示文本,但没有任何显示。

 LocationButton = [[UIButton alloc] init];

 UIImage * Location_buttonImages = [UIImage imageNamed:@"button~iphone.png"];

 [LocationButton setTitle:@"Loca" forState:UIControlStateNormal];
 [LocationButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

 [LocationButton setImage:Location_buttonImages forState:UIControlStateNormal];
 [LocationButton setImage:[UIImage imageNamed:
 @"button_select~iphone.png"]  
 forState:UIControlStateSelected];

  LocationButton.frame =  CGRectMake(20,212,90,40);

 [LocationButton addTarget:self action:
 @selector(action:) forControlEvents:UIControlEventTouchUpInside];

  [self.view addSubview:LocationButton];

我可以看到图像,但看不到文字。请帮忙!

4

1 回答 1

0
 [LocationButton setImage:Location_buttonImages forState:UIControlStateNormal];
 [LocationButton setImage:[UIImage imageNamed:@"button_select~iphone.png"]  forState:UIControlStateSelected];

您在标题上叠加图像,以便没有标题显示。更改为 setBackgroundImage:forState

 [LocationButton setBackgroundImage:Location_buttonImages forState:UIControlStateNormal];
 [LocationButton setBackgroundImage:[UIImage imageNamed:@"button_select~iphone.png" forState:UIControlStateSelected];
于 2013-04-15T23:49:28.100 回答