简体   繁体   English

如何快速在 UIImageView 上添加 UIView

[英]How to add a UIView over a UIImageView in swift

I am trying to make a feature where a user can see if someone is online or offline.我正在尝试制作一个功能,让用户可以查看某人是在线还是离线。 If there are online there is a small green dot on the image, and red if offline.如果在线,则图像上有一个小绿点,如果离线,则为红色。 How can I build this?我怎样才能建立这个? I have the circle image working but I am not sure how to add the green dot on it.我有圆形图像工作,但我不知道如何在上面添加绿点。 I am using Storyboards and UINibs.我正在使用故事板和 UINIb。 So I assumed I would need to make a UIView, not sure exactly how to place it.所以我假设我需要制作一个 UIView,但不确定如何放置它。

I can build this in Swift UI, so is it possible to buildit in swiftUI, and add that image to a UICollectionView Cell?我可以在 Swift UI 中构建它,那么是否可以在 swiftUI 中构建它,并将该图像添加到 UICollectionView 单元格?

Just palce a label with a "."只需在标签上加上“。” text in it, make the font as big as you would like it to be, apply constrains on it and then just change: myLabel.textColor = UIColor.green / myLalbel.textColor = UIColor.gray or whatever fits you, also note that you can apply centering of the text inside the label.文本,使字体尽可能大,对其应用约束,然后更改: myLabel.textColor = UIColor.green / myLalbel.textColor = UIColor.gray 或任何适合你的,还要注意你可以应用标签内的文本居中。

I went with adding a UIImageView over that image, and used the SFSymbol "circle.fill"我在该图像上添加了 UIImageView,并使用了 SFSymbol“circle.fill”

I then used the ternary operator to determine the state.然后我使用三元运算符来确定状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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