简体   繁体   English

如何在iOS Swift中实现UIImageView中嵌入的标签,如图所示?

[英]How to achieve label embededd in UIImageView in iOS Swift like shown in image?

在UIImageView中编辑Button / Label

I want to achieve label/Button embededd in UIImageView in iOS Swift like shown in image.Has anyone done that? 我想在iOS Swift中实现UIImageView中嵌入的标签/按钮,如图所示。有人这样做过吗?

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 ,包含UIImageViewUILabel 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM