我创建了一个UILabel
,它根据字符设置高度。我需要在可调整大小的UILable
下创建一些UIImageView
。这是我创建标签的方法:
let productDescriptionLabel = UILabel(frame: CGRect(x: 10, y: imageViewHeight + 10, width: viewWidth - 20, height: 0))
productDescriptionLabel.textColor = UIColor.darkGray
productDescriptionLabel.textAlignment = .right
productDescriptionLabel.text = productsDescriptionArray!
productDescriptionLabel.font = productDescriptionLabel.font.withSize(self.view.frame.height * self.relativeFontConstant)
productDescriptionLabel.numberOfLines = 0
let attrString = NSMutableAttributedString(string: productDescriptionLabel.text!)
let style = NSMutableParagraphStyle()
style.lineSpacing = 10
style.minimumLineHeight = 20
attrString.addAttribute(NSAttributedStringKey.paragraphStyle, value: style, range: NSRange(location: 0, length: (productDescriptionLabel.text?.characters.count)!))
productDescriptionLabel.attributedText = attrString
productDescriptionLabel.sizeToFit()
productDescriptionLabel.lineBreakMode = .byWordWrapping
contentScrollView.addSubview(productDescriptionLabel)
好吧,我想知道如何定义 UIImageView
y:
使其位于标签正下方?
最佳答案
希望这对您有帮助。创建标签后创建 imageView。
let imageView = UIImageView(frame: CGRect(x: 10, y: imageViewHeight + 10 + productDescriptionLabel.frame.size.height, width: viewWidth - 20, height: 0))
关于ios - View 的位置低于自调整大小的 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070286/