我试图在按钮上显示文本,但是什么也没显示。

 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];

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

===============>>#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];

  ask by Akshay translate from so

未解决问题?本站智能推荐: