如何在 iOS Swift 中实现嵌入 UIImageView 的标签,如图所示?
How to achieve label embededd in UIImageView in iOS Swift like shown in image?
我想实现 label/Button 嵌入到 iOS Swift 中的 UIImageView 中,如 image.Has 中所示,有人做过吗?
将 UIView
clipsToBounds
属性 设置为 YES
的正方形 UIView
,其中包含 UIImageView
和 UILabel
。图像视图应覆盖所有视图框架。标签应位于图像视图上方的视图底部。然后为视图层设置适当的角半径(视图高度的一半)并将其 masksToBounds
属性 设置为 YES
。就是这样
你只需要玩玩 UIView、UILabel 和 UIImageView。
您的视图层次结构如下所示...
- UIView (mainView)
- UIImageView (imageView)
- UILabel
你需要mainView.clipsToBounds = true
这样在给它圆角半径后,它的子视图不会超出它的父视图的范围。
对于imageView,您可以根据需要将其内容模式设置为aspect fill/aspect fit。
我想实现 label/Button 嵌入到 iOS Swift 中的 UIImageView 中,如 image.Has 中所示,有人做过吗?
将 UIView
clipsToBounds
属性 设置为 YES
的正方形 UIView
,其中包含 UIImageView
和 UILabel
。图像视图应覆盖所有视图框架。标签应位于图像视图上方的视图底部。然后为视图层设置适当的角半径(视图高度的一半)并将其 masksToBounds
属性 设置为 YES
。就是这样
你只需要玩玩 UIView、UILabel 和 UIImageView。
您的视图层次结构如下所示...
- UIView (mainView)
- UIImageView (imageView)
- UILabel
你需要mainView.clipsToBounds = true
这样在给它圆角半径后,它的子视图不会超出它的父视图的范围。
对于imageView,您可以根据需要将其内容模式设置为aspect fill/aspect fit。