Anonymous
Текст не переносится
Сообщение
Anonymous » 06 янв 2025, 02:25
У меня есть следующий текст в поле. Проверьте скриншот. По какой-то причине текст не переносится, хотя у меня есть следующий код. Как это исправить?
Код: Выделить всё
import Foundation
import UIKit
import SDWebImage
// MARK: - Custom Collection View Cell
class CollectionViewCell: UICollectionViewCell {
private let imageView = UIImageView()
private let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
// ImageView Setup
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.layer.masksToBounds = true
// Title Label Setup
titleLabel.font = UIFont(name: "Inter-Regular", size: 16)
titleLabel.textColor = .black
titleLabel.textAlignment = .left
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.numberOfLines = 0
contentView.addSubview(imageView)
contentView.addSubview(titleLabel)
contentView.backgroundColor = .white
contentView.layer.cornerRadius = 8
contentView.layer.borderWidth = 1
contentView.layer.borderColor = UIColor.lightGray.cgColor
imageView.translatesAutoresizingMaskIntoConstraints = false
titleLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
imageView.topAnchor.constraint(equalTo: contentView.topAnchor),
imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
imageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
imageView.heightAnchor.constraint(equalToConstant: 100),
titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 8),
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10),
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 10),
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(title: String, imageName: String) {
titleLabel.text = title
imageView.sd_setImage(with: URL(string: imageName), placeholderImage: UIImage(named: "personalfinance"))
}
}
Подробнее здесь:
https://stackoverflow.com/questions/793 ... oesnt-wrap
1736119547
Anonymous
У меня есть следующий текст в поле. Проверьте скриншот. По какой-то причине текст не переносится, хотя у меня есть следующий код. Как это исправить? [code]import Foundation import UIKit import SDWebImage // MARK: - Custom Collection View Cell class CollectionViewCell: UICollectionViewCell { private let imageView = UIImageView() private let titleLabel = UILabel() override init(frame: CGRect) { super.init(frame: frame) // ImageView Setup imageView.contentMode = .scaleAspectFill imageView.clipsToBounds = true imageView.layer.masksToBounds = true // Title Label Setup titleLabel.font = UIFont(name: "Inter-Regular", size: 16) titleLabel.textColor = .black titleLabel.textAlignment = .left titleLabel.lineBreakMode = .byWordWrapping titleLabel.numberOfLines = 0 contentView.addSubview(imageView) contentView.addSubview(titleLabel) contentView.backgroundColor = .white contentView.layer.cornerRadius = 8 contentView.layer.borderWidth = 1 contentView.layer.borderColor = UIColor.lightGray.cgColor imageView.translatesAutoresizingMaskIntoConstraints = false titleLabel.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ imageView.topAnchor.constraint(equalTo: contentView.topAnchor), imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), imageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), imageView.heightAnchor.constraint(equalToConstant: 100), titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 8), titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10), titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 10), titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) ]) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func configure(title: String, imageName: String) { titleLabel.text = title imageView.sd_setImage(with: URL(string: imageName), placeholderImage: UIImage(named: "personalfinance")) } } [/code] [img]https://i.sstatic.net/GPr1wxPQ.png[/img] Подробнее здесь: [url]https://stackoverflow.com/questions/79331725/text-doesnt-wrap[/url]