带有子视图的 UILabel
由于某些原因,我必须有一个带有自定义背景视图的 UILabel,我想通过 [label addSubview:backgroundView] 来实现。
背景渲染良好,但标签文本不显示。
我不能做的是将背景颜色与图案图像一起使用。
For some reasons I have to have a UILabel with a custom background view which I wanted to achieve by [label addSubview:backgroundView].
The background renders fine, but the Labels text does not appear.
What I can't do is using the background color with a pattern image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
编辑:
我发现了一些不确定它如何工作的东西。尝试使用backgroundColor属性。
比如:
太好了,我又迟到了......
Try
Edit:
I found something not sure how it would work tho. Try using the backgroundColor property.
Something like:
Great, I was late with this again...
确实是一个旧线程,但我遇到了同样的问题,并认为我的解决方案可能会帮助某人(使用 PureLayout 和 swift 4)并以编程方式添加视图。
viewController 中的示例用法:
现在您只需添加此视图并根据需要以编程方式设置约束即可。
对于此实现,您需要 UIView 扩展 .wrapperOnTopOf ,其实现如下:
Really an old thread but I faced the same issue, and figured my solution might help someone (Using PureLayout and swift 4) and programmatically adding the views.
Sample usage in your viewController:
Now you can just add this view and setup the constraints programmatically as you like.
For this implementation you need the UIView extension .wrapperOnTopOf which is implemented like:
当我读了更多的帖子时,我不得不重新考虑并最终使用 UIView 的子类。正如我的帖子和评论中所说,并不可取,但终于可以工作了。
As I've read some more posts I had to re-consider and in the end use a subclasses UIView. Not preferable as said in my post and comment, but finally working.