Roze-im / ContextualMenu

A replacement for native iOS context menu allowing adding an accessoryView à-la iMessage
MIT License
4 stars 0 forks source link

Does not work #1

Open yarodevuci opened 1 month ago

yarodevuci commented 1 month ago

I was hoping to see an example of emojis but instead some random simple view which does not make any sense!

I tried to recreate a view with emojis but it's not even showing up... Please help

yarodevuci commented 1 month ago

@roze-im

yarodevuci commented 1 month ago
lazy var accessoryView3: UIView = {
        let containerView = UIView()
        containerView.backgroundColor = .darkGray
        containerView.layer.cornerRadius = 10
        containerView.layer.masksToBounds = true
        containerView.frame = CGRect(x: 0, y: 0, width: 300, height: 80) // Set initial size

        let scrollView = UIScrollView()
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.frame = containerView.bounds.insetBy(dx: 10, dy: 10) // Set scrollView frame inside containerView
        scrollView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        let stackView = UIStackView()
        stackView.axis = .horizontal
        stackView.distribution = .fill
        stackView.alignment = .center
        stackView.spacing = 10
        stackView.frame = CGRect(x: 0, y: 0, width: containerView.bounds.width - 20, height: 80) // Set stackView frame
        stackView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        // Add emojis to the stack view
        let emojis = ["😄", "🔥", "😢", "👍", "👎", "🎉", "💯", "👏", "😎", "🤔", "😜"]
        for emoji in emojis {
            let button = UIButton(type: .system)
            button.setTitle(emoji, for: .normal)
            button.titleLabel?.font = .systemFont(ofSize: 32)
            button.addTarget(self, action: #selector(onEmojiButtonTapped(_:)), for: .touchUpInside)
            stackView.addArrangedSubview(button)
        }

        // Add stack view to scroll view
        scrollView.addSubview(stackView)

        // Calculate content size manually
        let contentWidth = stackView.frame.width
        let contentHeight = stackView.frame.height
        scrollView.contentSize = CGSize(width: contentWidth, height: contentHeight)

        // Add scroll view to container view
        containerView.addSubview(scrollView)

        return containerView
    }()