У меня есть следующий код < /p>
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.bounces = true
self.view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
scrollView.topAnchor.constraint(equalTo: progressView.bottomAnchor, constant: 20),
scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
])
// Create the UILabels, UIImageView, and UIButton
let titleLabel = UILabel()
titleLabel.text = "Your Intelligence Types"
titleLabel.font = UIFont(name: "Inter-Bold", size: 20)
titleLabel.textAlignment = .center
titleLabel.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(titleLabel)
// Set constraints for the stackView
NSLayoutConstraint.activate([
titleLabel.topAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.topAnchor, constant: 20),
titleLabel.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
titleLabel.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -20),
titleLabel.heightAnchor.constraint(equalToConstant: 30)
])
// Create the UILabels, UIImageView, and UIButton
let descriptionLbl = UILabel()
descriptionLbl.text = "Different types of intelligence highlight the diverse ways people think, solve problems, and interact with the world around them."
descriptionLbl.font = UIFont(name: "Inter-Regular", size: 14)
descriptionLbl.textAlignment = .left
descriptionLbl.numberOfLines = 0
descriptionLbl.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(descriptionLbl)
// Set constraints for the stackView
NSLayoutConstraint.activate([
descriptionLbl.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 20),
descriptionLbl.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
descriptionLbl.widthAnchor.constraint(equalToConstant: 350),
descriptionLbl.heightAnchor.constraint(equalToConstant: 60)
])
var previousProgressView : UIProgressView? = nil
let previousTitleHeight: CGFloat = 30
let progressViewHeight: CGFloat = 20
let labelHeight: CGFloat = 20
let verticalSpacing: CGFloat = 20
var n = 0;
for (key, value) in totalTypes {
let typeLabel = UILabel()
typeLabel.text = key
typeLabel.font = UIFont(name: "Inter-Bold", size: 16)
typeLabel.textAlignment = .left
typeLabel.translatesAutoresizingMaskIntoConstraints = false
let iprogressView = UIProgressView(progressViewStyle: .bar)
iprogressView.trackTintColor = UIColor(red: 0.07, green: 0.45, blue: 0.87, alpha: 0.1)
iprogressView.tintColor = UIColor(red: 0.07, green: 0.45, blue: 0.87, alpha: 1.00)
iprogressView.layer.cornerRadius = 4
iprogressView.clipsToBounds = true
iprogressView.setProgress(Float(userTypes[key] ?? 0) / Float(value), animated: true)
iprogressView.translatesAutoresizingMaskIntoConstraints = false
let transform : CGAffineTransform = CGAffineTransform(scaleX: 1.0, y: 3.0)
iprogressView.transform = transform
let progressLabel = UILabel()
let progressValue = round(((Float(userTypes[key] ?? 0) / Float(value)) * 100) * 100) / 100
progressLabel.text = "\(progressValue) %"
progressLabel.translatesAutoresizingMaskIntoConstraints = false
progressLabel.font = UIFont(name: "Inter-Regular", size: 16)
scrollView.addSubview(typeLabel)
scrollView.addSubview(iprogressView)
scrollView.addSubview(progressLabel)
NSLayoutConstraint.activate([
typeLabel.topAnchor.constraint(equalTo: previousProgressView?.bottomAnchor ?? descriptionLbl.bottomAnchor, constant: previousProgressView == nil ? verticalSpacing : verticalSpacing),
typeLabel.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
typeLabel.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -20),
typeLabel.heightAnchor.constraint(equalToConstant: 20),
iprogressView.topAnchor.constraint(equalTo: typeLabel.bottomAnchor, constant: 20),
iprogressView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
iprogressView.widthAnchor.constraint(equalToConstant: 200),
iprogressView.heightAnchor.constraint(equalToConstant: 3),
// Position the label next to the progressView
progressLabel.leadingAnchor.constraint(equalTo: iprogressView.trailingAnchor, constant: 10),
progressLabel.centerYAnchor.constraint(equalTo: iprogressView.centerYAnchor)
])
// Update the previousProgressView reference
previousProgressView = iprogressView
n += 1
}
// Set the content size of the scrollView
let totalContentHeight = (CGFloat(totalTypes.count) * (labelHeight + progressViewHeight + verticalSpacing + CGFloat(100))) + verticalSpacing + CGFloat(2000)
scrollView.contentSize = CGSize(width: self.view.frame.width, height: totalContentHeight)
< /code>
Проблема в том, что Scrollview не будет прокручивать, даже если я устанавливаю размер контента. Как я могу это решить?
Подробнее здесь: https://stackoverflow.com/questions/789 ... ont-scroll
Просмотр прокрутки не прокрутите [дублировать] ⇐ IOS
Программируем под IOS
-
Anonymous
1749989848
Anonymous
У меня есть следующий код < /p>
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.bounces = true
self.view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
scrollView.topAnchor.constraint(equalTo: progressView.bottomAnchor, constant: 20),
scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
])
// Create the UILabels, UIImageView, and UIButton
let titleLabel = UILabel()
titleLabel.text = "Your Intelligence Types"
titleLabel.font = UIFont(name: "Inter-Bold", size: 20)
titleLabel.textAlignment = .center
titleLabel.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(titleLabel)
// Set constraints for the stackView
NSLayoutConstraint.activate([
titleLabel.topAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.topAnchor, constant: 20),
titleLabel.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
titleLabel.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -20),
titleLabel.heightAnchor.constraint(equalToConstant: 30)
])
// Create the UILabels, UIImageView, and UIButton
let descriptionLbl = UILabel()
descriptionLbl.text = "Different types of intelligence highlight the diverse ways people think, solve problems, and interact with the world around them."
descriptionLbl.font = UIFont(name: "Inter-Regular", size: 14)
descriptionLbl.textAlignment = .left
descriptionLbl.numberOfLines = 0
descriptionLbl.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(descriptionLbl)
// Set constraints for the stackView
NSLayoutConstraint.activate([
descriptionLbl.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 20),
descriptionLbl.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
descriptionLbl.widthAnchor.constraint(equalToConstant: 350),
descriptionLbl.heightAnchor.constraint(equalToConstant: 60)
])
var previousProgressView : UIProgressView? = nil
let previousTitleHeight: CGFloat = 30
let progressViewHeight: CGFloat = 20
let labelHeight: CGFloat = 20
let verticalSpacing: CGFloat = 20
var n = 0;
for (key, value) in totalTypes {
let typeLabel = UILabel()
typeLabel.text = key
typeLabel.font = UIFont(name: "Inter-Bold", size: 16)
typeLabel.textAlignment = .left
typeLabel.translatesAutoresizingMaskIntoConstraints = false
let iprogressView = UIProgressView(progressViewStyle: .bar)
iprogressView.trackTintColor = UIColor(red: 0.07, green: 0.45, blue: 0.87, alpha: 0.1)
iprogressView.tintColor = UIColor(red: 0.07, green: 0.45, blue: 0.87, alpha: 1.00)
iprogressView.layer.cornerRadius = 4
iprogressView.clipsToBounds = true
iprogressView.setProgress(Float(userTypes[key] ?? 0) / Float(value), animated: true)
iprogressView.translatesAutoresizingMaskIntoConstraints = false
let transform : CGAffineTransform = CGAffineTransform(scaleX: 1.0, y: 3.0)
iprogressView.transform = transform
let progressLabel = UILabel()
let progressValue = round(((Float(userTypes[key] ?? 0) / Float(value)) * 100) * 100) / 100
progressLabel.text = "\(progressValue) %"
progressLabel.translatesAutoresizingMaskIntoConstraints = false
progressLabel.font = UIFont(name: "Inter-Regular", size: 16)
scrollView.addSubview(typeLabel)
scrollView.addSubview(iprogressView)
scrollView.addSubview(progressLabel)
NSLayoutConstraint.activate([
typeLabel.topAnchor.constraint(equalTo: previousProgressView?.bottomAnchor ?? descriptionLbl.bottomAnchor, constant: previousProgressView == nil ? verticalSpacing : verticalSpacing),
typeLabel.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
typeLabel.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -20),
typeLabel.heightAnchor.constraint(equalToConstant: 20),
iprogressView.topAnchor.constraint(equalTo: typeLabel.bottomAnchor, constant: 20),
iprogressView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 20),
iprogressView.widthAnchor.constraint(equalToConstant: 200),
iprogressView.heightAnchor.constraint(equalToConstant: 3),
// Position the label next to the progressView
progressLabel.leadingAnchor.constraint(equalTo: iprogressView.trailingAnchor, constant: 10),
progressLabel.centerYAnchor.constraint(equalTo: iprogressView.centerYAnchor)
])
// Update the previousProgressView reference
previousProgressView = iprogressView
n += 1
}
// Set the content size of the scrollView
let totalContentHeight = (CGFloat(totalTypes.count) * (labelHeight + progressViewHeight + verticalSpacing + CGFloat(100))) + verticalSpacing + CGFloat(2000)
scrollView.contentSize = CGSize(width: self.view.frame.width, height: totalContentHeight)
< /code>
Проблема в том, что Scrollview не будет прокручивать, даже если я устанавливаю размер контента. Как я могу это решить?
Подробнее здесь: [url]https://stackoverflow.com/questions/78911089/scroll-view-wont-scroll[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия