| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // MOBubbleToastView.swift
- // MiMoLive
- //
- // Created by OneeChan on 2025/10/17.
- //
- import Foundation
- import UIKit
- @objcMembers
- class MOBubbleToastView: UIView {
- private let title = UILabel()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupViews()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func showAt(_ targetView: UIView, title: String) {
- guard let view = targetView.superview else { return }
- self.title.text = title
- view.addSubview(self)
- makeConstraints { make in
- make.centerX.equalTo(targetView)
- make.bottom.equalTo(targetView.sTop).offset(-7)
- }
-
- MODelayTask.perform(delay: 3) { [weak self] in
- guard let self else { return }
- removeFromSuperview()
- }
- }
- }
- extension MOBubbleToastView {
- private func setupViews() {
- let text = buildTextView()
- addSubview(text)
- text.makeConstraints { make in
- make.leading.top.trailing.equalToSuperview()
- }
-
- let arrow = buildArrow()
- addSubview(arrow)
- arrow.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.bottom.equalToSuperview()
- make.top.equalTo(text.sBottom).offset(-1)
- }
- }
-
- private func buildTextView() -> UIView {
- let container = UIView()
- container.backgroundColor = .black.withAlphaComponent(0.8)
- container.layer.cornerRadius = 10
-
- title.textColor = .white
- title.font = .systemFont(ofSize: 13)
- container.addSubview(title)
- title.makeConstraints { make in
- make.edges.equalToSuperview().inset(UIEdgeInsets(top: 7, left: 12, bottom: 7, right: 12))
- }
-
- return container
- }
-
- private func buildArrow() -> UIView {
- let arrow = UIImageView()
- arrow.image = .init(named: "icon_guilde_arrow_down")?.withRenderingMode(.alwaysTemplate)
- arrow.tintColor = .black.withAlphaComponent(0.8)
-
- return arrow
- }
- }
- //import SwiftUI
- //
- //struct MOBubbleToastViewPreview: UIViewRepresentable {
- // func makeUIView(context: Context) -> some UIView {
- // let view = UIView()
- //
- // let button = UIButton()
- // button.backgroundColor = .black
- // view.addSubview(button)
- // button.makeConstraints { make in
- // make.center.equalToSuperview()
- // }
- //
- // let list = MOBubbleToastView()
- // list.showAt(button, title: "123123")
- //
- // return view
- // }
- //
- // func updateUIView(_ uiView: UIViewType, context: Context) { }
- //}
- //
- //#Preview {
- // MOBubbleToastViewPreview()
- //}
|