具有自定义背景的 UIButton 失去标题 [英] UIButton with custom background loses title
本文介绍了具有自定义背景的 UIButton 失去标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个自定义按钮,但是在设置图像后,我注意到标题消失了,认为这是因为我在按钮上添加了一个图像,与标题重叠.
I was trying to create a custom button, but after setting the image, I noticed that the title disappears, it think this is because I add an image to the button, which overlaps the title.
UIImage *pickerBg = [UIImage imageNamed:@"btn_picker.png"];
UIImage *pickerBg_highlighted = [UIImage imageNamed:@"btn_picker_highlighted.png"];
[projectBtn setImage:pickerBg forState:UIControlStateNormal];
[projectBtn setImage:pickerBg_highlighted forState:UIControlStateHighlighted];
还有其他方法可以做到这一点吗?
Is there another way on how to do this?
推荐答案
使用您需要的标题创建一个 UILabel,然后将其作为子视图添加到您的 UIButton.
Create a UILabel with the title you need, then add it as a subview to your UIButton.
这篇关于具有自定义背景的 UIButton 失去标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文