我搜索了解决方案,我在这里看到了几个类似的帖子,但我找不到答案。我正在尝试添加一个使用图像设置的 UIButton(仅背景颜色也很好),我想在此图像上添加文本
到目前为止,这是我的代码:
labelSorry.text = @"לא נמצאו תוצאות.";//add text
//add button.
Request =[UIButton buttonWithType:UIButtonTypeCustom];
UIImage *requestimg = [UIImage imageNamed:@"requestcontact_resize2.png"];
Request.frame = CGRectMake(0.0, 120, 320.0, 30.0);
Request.titleLabel.textAlignment = NSTextAlignmentRight;
// Request.titleLabel.textColor = UIColorFromRGB(0xffffff);
[Request setBackgroundImage:requestimg forState:UIControlStateNormal];
Request.imageView.image = [UIImage imageNamed:@"requestcontact_resize2.png"];//see no image :( this is kidding me
// [Request setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0.0, 120, 320.0, 30.0)];///You can replace it with your own dimensions.
label.textColor = UIColorFromRGB(0xffffff);
label.text = @"בקש פרטי איש קשר";
[Request addSubview:label];
//[Request setBackgroundColor:UIColorFromRGB(0x704c9f)];
Request.titleLabel.text = @"בקש פרטי איש קשר";
[Request addTarget:self action:@selector(requestDetails) forControlEvents:UIControlEventTouchUpInside];
[noResultsView addSubview:Request];
[self.view addSubview:noResultsView];
我可以看到按钮的背景,但我看不到任何文字:(请也许有人可以启发我?
如您所见,我尝试了各种解决方案(我将它们放在评论中),但都没有奏效。
PS我没有使用xib。
任何帮助将不胜感激。