【发布时间】:2021-06-28 23:57:35
【问题描述】:
我有一个 ViewController,它有四个 UITextView 和四个 UILabel。我有他们每个人的文本,它们在一个数组中。我试图使 UITextViews 和 UILabels 在彼此之间具有相同长度的受限距离,无论字段的长度如何。每次我尝试对 ViewController 应用约束时,它都会弄乱上面的所有内容(标签、文本视图等)。 ViewController 有一个滚动视图。以下是截图和代码:
import UIKit
class DetailViewController: UIViewController {
var name = ""
var img: UIImage?
var desc = ""
var healingProp = ""
var spiritualProp = ""
var emotionalProp = ""
@IBOutlet weak var detailCrystalPhotoImageView: UIImageView!
// about the crystal
@IBOutlet weak var crystalDescriptionTextView: UITextView!
@IBOutlet weak var backgroundInfoLabel: UILabel!
// healing properties
@IBOutlet weak var healingPropertiesLabel: UILabel!
@IBOutlet weak var healingPropertiesInfoTextView: UITextView!
@IBOutlet weak var scrollView: UIScrollView!
// spiritual properties
@IBOutlet weak var spiritualPropertiesLabel: UILabel!
@IBOutlet weak var spiritualPropertiesInfoTextView: UITextView!
// emotional properties
@IBOutlet weak var emotionalPropertiesLabel: UILabel!
@IBOutlet weak var emotionalPropertiesInfoTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// sets up scroll view
scrollView.contentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height+1000)
// displays crystal title and crystal image
title = name
detailCrystalPhotoImageView.image = img
// display background label and text
backgroundInfoLabel.text = String("About " + name + " ℹ️")
backgroundInfoLabel.font = UIFont.systemFont(ofSize: 24, weight: .light)
// sets up crystal summary
crystalDescriptionTextView.text = desc
crystalDescriptionTextView.font = UIFont.systemFont(ofSize: 18, weight: .thin)
// display healing properties label and text
healingPropertiesLabel.text = String("Healing Properties ????")
healingPropertiesLabel.font = UIFont.systemFont(ofSize: 24, weight: .light)
healingPropertiesInfoTextView.text = healingProp
healingPropertiesInfoTextView.font = UIFont.systemFont(ofSize: 18, weight: .thin)
healingPropertiesInfoTextView.sizeToFit()
// display spiritual properties label and text
spiritualPropertiesLabel.text = String("Spiritual Properties ????️")
spiritualPropertiesLabel.font = UIFont.systemFont(ofSize: 24, weight: .light)
spiritualPropertiesInfoTextView.text = spiritualProp
spiritualPropertiesInfoTextView.font = UIFont.systemFont(ofSize: 18, weight: .thin)
//display emotional properties label and text
emotionalPropertiesLabel.text = String("Emotional Properties ????")
emotionalPropertiesLabel.font = UIFont.systemFont(ofSize: 24, weight: .light)
emotionalPropertiesInfoTextView.text = emotionalProp
emotionalPropertiesInfoTextView.font = UIFont.systemFont(ofSize: 18, weight: .thin)
}
}
【问题讨论】:
-
你的描述与你的问题标题无关!!!
标签: ios swift iphone xcode ipad