ios - View 的位置低于自调整大小的 UILabel

标签 ios swift xcode uilabel

我创建了一个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/

相关文章:

iphone - 一个 XCode 项目,两个目标,两个应用程序 (iPhone/iPad),不是通用应用程序

objective-c - 如何在 Cocos2D 中的移动 Sprite 上添加文本?

swift - 使用 Swift 3 在 macOS 10.12 的第二个屏幕上使用 NSWindow 全屏显示?

ios - 更改选项卡项的非事件颜色

swift - UnsafePointer<UInt8> 函数参数行为的字符串值

ios - 如何动态生成CoreData对象

iphone - 如何在 textView 中显示字符串而不是地址

ios - stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) 在 Swift 中返回 Optional

ios - 如何在每个 View Controller 中使用变量?

ios - 为 WatchKit 配置应用程序传输安全性(LaunchServicesError 错误 0。)