[英]How to achieve label embededd in UIImageView in iOS Swift like shown in image?
You just need to play with UIView, UILabel And UIImageView. 你只需要玩UIView,UILabel和UIImageView。
You view hierarchy will be like below... 您查看的层次结构将如下所示...
- UIView (mainView)
- UIImageView (imageView)
- UILabel
You need to make mainView.clipsToBounds = true
so that after giving corner radius to it, it's subview will not go beyond its superview's bounds. 你需要使
mainView.clipsToBounds = true
以便在给角落半径后,它的子视图不会超出其superview的界限。
For imageView, you can set its content mode to aspect fill/ aspect fit as per your requirement. 对于imageView,您可以根据需要将其内容模式设置为纵横填充/纵横比。
Have a square UIView
with clipsToBounds
property set to YES
which contains UIImageView
and UILabel
. 有一个方形
UIView
,其clipsToBounds
属性设置为YES
,包含UIImageView
和UILabel
。 The image view should cover all the view frame. 图像视图应覆盖所有视图框。 The label should be positioned at the bottom of the view over the image view.
标签应位于图像视图上方视图的底部。 Then just set appropriate corner radius (half of the view's height) for the view's layer and set its
masksToBounds
property to YES
. 然后只需为视图的图层设置适当的角半径(视图高度的一半),并将其
masksToBounds
属性设置为YES
。 That's it 而已
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.