Скриншот моей проблемы < /p>
У меня есть проблема, в которой граница основного представления пользовательского класса Uiview, который у меня есть, идет на вершину Rankbadgeview в этом пользовательском классе. Я не могу на всю жизнь понять, почему. Я попытался вывести подвеску Рандбэджвью на фронт вместе с Uilabel внутри и до сих пор не работает. Кто -нибудь может помочь мне определить проблему? < /P>
class LeaderboardCircleView: UIView {
private let mainLabel = UILabel()
let rankBadgeView = UIView()
private let rankLabel = UILabel()
private let scoreLabel = UILabel()
init(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
super.init(frame: .zero)
setupViews()
configure(mainText: mainText, rankText: rankText, backgroundColor: backgroundColor, score: score)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func updateScoreLabelWith(score: Int) {
let trophyAttachment = NSTextAttachment()
trophyAttachment.image = UIImage(systemName: "trophy.fill")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
trophyAttachment.bounds = CGRect(x: 0, y: -2, width: 16, height: 16)
let trophyString = NSAttributedString(attachment: trophyAttachment)
let scoreString = NSAttributedString(string: " \(score) pts", attributes: [
.font: AppStyle.shared.headerFont(size: 12),
.foregroundColor: UIColor.darkGray
])
let fullScoreText = NSMutableAttributedString()
fullScoreText.append(trophyString)
fullScoreText.append(scoreString)
scoreLabel.attributedText = fullScoreText
}
private func setupViews() {
layer.borderWidth = 2
layer.borderColor = AppStyle.shared.primaryColor?.cgColor
translatesAutoresizingMaskIntoConstraints = false
clipsToBounds = false
mainLabel.translatesAutoresizingMaskIntoConstraints = false
mainLabel.textAlignment = .center
mainLabel.adjustsFontSizeToFitWidth = true
mainLabel.minimumScaleFactor = 0.5
mainLabel.numberOfLines = 2
mainLabel.font = AppStyle.shared.headerFont(size: 18)
mainLabel.textColor = .white
addSubview(mainLabel)
rankBadgeView.translatesAutoresizingMaskIntoConstraints = false
rankBadgeView.clipsToBounds = true
rankBadgeView.backgroundColor = AppStyle.shared.primaryColor
rankBadgeView.layer.zPosition = 1 // Sends it behind the border
addSubview(rankBadgeView)
rankLabel.translatesAutoresizingMaskIntoConstraints = false
rankLabel.textAlignment = .center
rankLabel.font = AppStyle.shared.headerFont(size: 12)
rankLabel.textColor = .white
rankBadgeView.addSubview(rankLabel)
scoreLabel.translatesAutoresizingMaskIntoConstraints = false
scoreLabel.textAlignment = .center
scoreLabel.adjustsFontSizeToFitWidth = true
scoreLabel.minimumScaleFactor = 0.5
scoreLabel.numberOfLines = 1
addSubview(scoreLabel)
NSLayoutConstraint.activate([
mainLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10),
mainLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10),
mainLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
mainLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
rankBadgeView.centerXAnchor.constraint(equalTo: centerXAnchor),
rankBadgeView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 12),
rankBadgeView.widthAnchor.constraint(equalToConstant: 30),
rankBadgeView.heightAnchor.constraint(equalToConstant: 30),
rankLabel.centerXAnchor.constraint(equalTo: rankBadgeView.centerXAnchor),
rankLabel.centerYAnchor.constraint(equalTo: rankBadgeView.centerYAnchor),
scoreLabel.topAnchor.constraint(equalTo: rankBadgeView.bottomAnchor, constant: 4),
scoreLabel.centerXAnchor.constraint(equalTo: centerXAnchor)
])
bringSubviewToFront(rankBadgeView)
rankBadgeView.bringSubviewToFront(scoreLabel)
}
private func configure(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
mainLabel.text = mainText
self.backgroundColor = backgroundColor
rankLabel.text = rankText
let trophyAttachment = NSTextAttachment()
trophyAttachment.image = UIImage(systemName: "trophy.fill")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
trophyAttachment.bounds = CGRect(x: 0, y: -2, width: 16, height: 16)
let trophyString = NSAttributedString(attachment: trophyAttachment)
let scoreString = NSAttributedString(string: " \(score) pts", attributes: [
.font: AppStyle.shared.headerFont(size: 12),
.foregroundColor: UIColor.darkGray
])
let fullScoreText = NSMutableAttributedString()
fullScoreText.append(trophyString)
fullScoreText.append(scoreString)
scoreLabel.attributedText = fullScoreText
}
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = bounds.width / 2
rankBadgeView.layer.cornerRadius = rankBadgeView.bounds.width / 2
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.2
layer.shadowRadius = 6.0
layer.shadowOffset = CGSize(width: 0, height: 4)
layer.masksToBounds = false
rankBadgeView.layer.shadowColor = UIColor.black.cgColor
rankBadgeView.layer.shadowOpacity = 0.2
rankBadgeView.layer.shadowRadius = 4.0
rankBadgeView.layer.shadowOffset = CGSize(width: 0, height: 2)
rankBadgeView.layer.masksToBounds = false
}
func update(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
configure(mainText: mainText, rankText: rankText, backgroundColor: backgroundColor, score: score)
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... other-view
Граница Main View в моем пользовательском классе Uiview находится на вершине другого представления ⇐ IOS
Программируем под IOS
1745846076
Anonymous
Скриншот моей проблемы < /p>
У меня есть проблема, в которой граница основного представления пользовательского класса Uiview, который у меня есть, идет на вершину Rankbadgeview в этом пользовательском классе. Я не могу на всю жизнь понять, почему. Я попытался вывести подвеску Рандбэджвью на фронт вместе с Uilabel внутри и до сих пор не работает. Кто -нибудь может помочь мне определить проблему? < /P>
class LeaderboardCircleView: UIView {
private let mainLabel = UILabel()
let rankBadgeView = UIView()
private let rankLabel = UILabel()
private let scoreLabel = UILabel()
init(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
super.init(frame: .zero)
setupViews()
configure(mainText: mainText, rankText: rankText, backgroundColor: backgroundColor, score: score)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func updateScoreLabelWith(score: Int) {
let trophyAttachment = NSTextAttachment()
trophyAttachment.image = UIImage(systemName: "trophy.fill")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
trophyAttachment.bounds = CGRect(x: 0, y: -2, width: 16, height: 16)
let trophyString = NSAttributedString(attachment: trophyAttachment)
let scoreString = NSAttributedString(string: " \(score) pts", attributes: [
.font: AppStyle.shared.headerFont(size: 12),
.foregroundColor: UIColor.darkGray
])
let fullScoreText = NSMutableAttributedString()
fullScoreText.append(trophyString)
fullScoreText.append(scoreString)
scoreLabel.attributedText = fullScoreText
}
private func setupViews() {
layer.borderWidth = 2
layer.borderColor = AppStyle.shared.primaryColor?.cgColor
translatesAutoresizingMaskIntoConstraints = false
clipsToBounds = false
mainLabel.translatesAutoresizingMaskIntoConstraints = false
mainLabel.textAlignment = .center
mainLabel.adjustsFontSizeToFitWidth = true
mainLabel.minimumScaleFactor = 0.5
mainLabel.numberOfLines = 2
mainLabel.font = AppStyle.shared.headerFont(size: 18)
mainLabel.textColor = .white
addSubview(mainLabel)
rankBadgeView.translatesAutoresizingMaskIntoConstraints = false
rankBadgeView.clipsToBounds = true
rankBadgeView.backgroundColor = AppStyle.shared.primaryColor
rankBadgeView.layer.zPosition = 1 // Sends it behind the border
addSubview(rankBadgeView)
rankLabel.translatesAutoresizingMaskIntoConstraints = false
rankLabel.textAlignment = .center
rankLabel.font = AppStyle.shared.headerFont(size: 12)
rankLabel.textColor = .white
rankBadgeView.addSubview(rankLabel)
scoreLabel.translatesAutoresizingMaskIntoConstraints = false
scoreLabel.textAlignment = .center
scoreLabel.adjustsFontSizeToFitWidth = true
scoreLabel.minimumScaleFactor = 0.5
scoreLabel.numberOfLines = 1
addSubview(scoreLabel)
NSLayoutConstraint.activate([
mainLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10),
mainLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10),
mainLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
mainLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
rankBadgeView.centerXAnchor.constraint(equalTo: centerXAnchor),
rankBadgeView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 12),
rankBadgeView.widthAnchor.constraint(equalToConstant: 30),
rankBadgeView.heightAnchor.constraint(equalToConstant: 30),
rankLabel.centerXAnchor.constraint(equalTo: rankBadgeView.centerXAnchor),
rankLabel.centerYAnchor.constraint(equalTo: rankBadgeView.centerYAnchor),
scoreLabel.topAnchor.constraint(equalTo: rankBadgeView.bottomAnchor, constant: 4),
scoreLabel.centerXAnchor.constraint(equalTo: centerXAnchor)
])
bringSubviewToFront(rankBadgeView)
rankBadgeView.bringSubviewToFront(scoreLabel)
}
private func configure(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
mainLabel.text = mainText
self.backgroundColor = backgroundColor
rankLabel.text = rankText
let trophyAttachment = NSTextAttachment()
trophyAttachment.image = UIImage(systemName: "trophy.fill")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
trophyAttachment.bounds = CGRect(x: 0, y: -2, width: 16, height: 16)
let trophyString = NSAttributedString(attachment: trophyAttachment)
let scoreString = NSAttributedString(string: " \(score) pts", attributes: [
.font: AppStyle.shared.headerFont(size: 12),
.foregroundColor: UIColor.darkGray
])
let fullScoreText = NSMutableAttributedString()
fullScoreText.append(trophyString)
fullScoreText.append(scoreString)
scoreLabel.attributedText = fullScoreText
}
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = bounds.width / 2
rankBadgeView.layer.cornerRadius = rankBadgeView.bounds.width / 2
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.2
layer.shadowRadius = 6.0
layer.shadowOffset = CGSize(width: 0, height: 4)
layer.masksToBounds = false
rankBadgeView.layer.shadowColor = UIColor.black.cgColor
rankBadgeView.layer.shadowOpacity = 0.2
rankBadgeView.layer.shadowRadius = 4.0
rankBadgeView.layer.shadowOffset = CGSize(width: 0, height: 2)
rankBadgeView.layer.masksToBounds = false
}
func update(mainText: String, rankText: String, backgroundColor: UIColor, score: Int) {
configure(mainText: mainText, rankText: rankText, backgroundColor: backgroundColor, score: score)
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79595632/main-views-border-in-my-custom-uiview-class-is-on-top-of-another-view[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия