mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
proper labels
This commit is contained in:
5 files changed
+46
-51
No files matched your search
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// EmojiCollectionFlowLayout.swift
|
||||
// StickerSlack
|
||||
//
|
||||
// Created by neon443 on 26/04/2026.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class EmojiCollectionFlowLayout: NSObject, UICollectionViewDelegateFlowLayout {
|
||||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
||||
let emojiName = pack
|
||||
}
|
||||
}
|
||||
@@ -108,16 +108,26 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
return cell
|
||||
}
|
||||
|
||||
// func collectionView(
|
||||
// _ collectionView: UICollectionView,
|
||||
// layout collectionViewLayout: UICollectionViewLayout,
|
||||
// sizeForItemAt indexPath: IndexPath
|
||||
// ) -> CGSize {
|
||||
// let defaultSize = CGSize(width: width, height: width)
|
||||
//
|
||||
// guard !hoarder.trie.dict.isEmpty else { return defaultSize }
|
||||
// let emojiName = pack.items[indexPath.item]
|
||||
// }
|
||||
func collectionView(
|
||||
_ collectionView: UICollectionView,
|
||||
layout collectionViewLayout: UICollectionViewLayout,
|
||||
sizeForItemAt indexPath: IndexPath
|
||||
) -> CGSize {
|
||||
let defaultSize = CGSize(width: width, height: width)
|
||||
|
||||
guard !hoarder.trie.dict.isEmpty else { return defaultSize }
|
||||
let emojiName = pack.items[indexPath.item]
|
||||
|
||||
let label = UILabel()
|
||||
label.font = .preferredFont(forTextStyle: .caption1)
|
||||
label.numberOfLines = 0
|
||||
label.text = emojiName
|
||||
let labelHeight = label.sizeThatFits(CGSize(width: width, height: .infinity)).height
|
||||
|
||||
print(width+labelHeight)
|
||||
|
||||
return CGSize(width: width, height: width+labelHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,30 @@ import UIKit
|
||||
|
||||
class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||
let label = UILabel()
|
||||
let spacer = UIView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
contentView.addSubview(spacer)
|
||||
spacer.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
label.font = .preferredFont(forTextStyle: .caption1)
|
||||
label.textAlignment = .center
|
||||
label.numberOfLines = 0
|
||||
contentView.addSubview(label)
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
spacer.topAnchor.constraint(equalTo: topAnchor),
|
||||
spacer.bottomAnchor.constraint(equalTo: label.topAnchor),
|
||||
spacer.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
spacer.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||
|
||||
label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||
])
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -33,20 +50,6 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell {
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||
])
|
||||
|
||||
// label.frame = contentView.bounds
|
||||
contentView.bringSubviewToFront(label)
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
label.text = nil
|
||||
|
||||
@@ -47,12 +47,15 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
|
||||
self.contentView.addSubview(hostingController.view)
|
||||
|
||||
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
hostingController.view.topAnchor.constraint(equalTo: contentView.topAnchor),
|
||||
hostingController.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||
hostingController.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
||||
])
|
||||
NSLayoutConstraint.activate(
|
||||
[
|
||||
hostingController.view.topAnchor.constraint(equalTo: contentView.topAnchor),
|
||||
// hostingController.view.bottomAnchor.constraint(equalTo: contentView.topAnchor, ),
|
||||
hostingController.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
||||
hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||
hostingController.view.heightAnchor.constraint(equalTo: hostingController.view.widthAnchor)
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||