如何为标签设置背景图像
我想在图像上显示一个数字,例如大小为 30*28 的徽章,将其放置在按钮图像上,
我有一个徽章图像要设置在按钮图像的顶部。 在徽章图像顶部,我应该能够显示文本或数字,并且我的徽章尺寸为 30*28。
因此,为了实现此目的,我想在按钮图像顶部设置一个标签,因此我想将标签背景设置为某个名为徽章图像的图像。
I want to display a number on image like badge of size 30*28, which is placed upon button image,
I have an badge image to set up on the top of button image..
on top of badge image I should able to display text or number and my badge size is 30*28.
so, for this to achieve I want to set a label on top of my button image and so I want to set label background to some image called badge image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在堆栈溢出本身中发现了这一点,因为上面的代码只给出了没有标签的背景,
这对我很有用
所以分享
请参阅:向 UILabel 添加背景图像
found this in stack overflow itself as the above code just gives the background without the label
was useful for me
so sharing
See: Adding Background image to UILabel
您无法将背景图像添加到 UILabel,但可以将 UIImageView 作为子视图添加到 UILabel。确保 UILabel 具有
backgroundColor = [UIColor clearColor];
以实现透明度。例如
应该有效。未经测试。
You can't add a background image to a UILabel, but you can add a UIImageView as a subview to a UILabel. Make sure the UILabel has
backgroundColor = [UIColor clearColor];
for transparency.E.g.
Should work. Untested.
要使图像适合您的UIview,尝试此代码
To make the image fit in your UIview, try this code