视图的位置低于自我大小UILabel

时间:2017-09-06 08:26:48

标签: ios swift xcode uilabel

我创建了一个UILabel,根据字符设置高度。我需要在可调整大小的UIImageView下创建一些UILable。以下是我创建标签的方法:

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:定义为在标签下面做什么?

1 个答案:

答案 0 :(得分:0)

希望这会对你有所帮助。标签创建后创建imageView。

let imageView = UIImageView(frame: CGRect(x: 10, y: imageViewHeight + 10 + productDescriptionLabel.frame.size.height, width: viewWidth - 20, height: 0))