如何在带有Swift 3的BWWalkthrough View Controller中添加标签?

我在我的应用程序中使用BWWalkthrough库来制作幻灯片图片。 我在每张幻灯片中添加标题和消息标签

在这里输入图像说明

我想翻译成每个标签。
所以,我将标签拖到IBOutlet并在ViewDidLoad添加NStranslation文本。
但是,当我运行代码时,我得到了致命的错误。
这是我的代码。
BWWalkthroughPageViewController.swift

  @IBOutlet weak var lblTitle1: UILabel! 

 override open func viewDidLoad() { super.viewDidLoad() lblTitle1.text = NSLocalizedString("Date:", comment: "") self.view.layer.masksToBounds = true subviewsSpeed = Array() for v in view.subviews{ speed.x += speedVariance.x speed.y += speedVariance.y if !notAnimatableViews.contains(v.tag) { subviewsSpeed.append(speed) } } } 

我在这些代码(BWWalkthroughViewController.swift)中出现错误。

 viewController.view.translatesAutoresizingMaskIntoConstraints = false 

lblTitle1.text = NSLocalizedString(“Date:”,comment:“”)

任何人都可以帮我吗?

做下面的事情,在所有页面添加一个标签,你可以添加更多的标签,就像同样的方式。

 override open func viewDidLoad() { super.viewDidLoad() self.view.layer.masksToBounds = true let sampleLabel:UILabel = UILabel() sampleLabel.frame = CGRect(x: 100, y: 100, width: 200, height: 200) sampleLabel.textAlignment = .center sampleLabel.text = "Hello this is iOS dev" sampleLabel.numberOfLines = 1 sampleLabel.textColor = .red sampleLabel.font=UIFont.systemFont(ofSize: 22) sampleLabel.backgroundColor = .yellow view.addSubview(sampleLabel) sampleLabel.translatesAutoresizingMaskIntoConstraints = false sampleLabel.heightAnchor.constraint(equalToConstant: 200).isActive = true sampleLabel.widthAnchor.constraint(equalToConstant: 200).isActive = true sampleLabel.centerXAnchor.constraint(equalTo: sampleLabel.superview!.centerXAnchor).isActive = true sampleLabel.centerYAnchor.constraint(equalTo: sampleLabel.superview!.centerYAnchor).isActive = true subviewsSpeed = Array() for v in view.subviews{ speed.x += speedVariance.x speed.y += speedVariance.y if !notAnimatableViews.contains(v.tag) { subviewsSpeed.append(speed) } } } 

更新

您可以通过下面的安全lblTitle1检查防止发生崩溃。

 override open func viewDidLoad() { super.viewDidLoad() if (lblTitle1) != nil { lblTitle1.text = NSLocalizedString("Date:", comment: "") } self.view.layer.masksToBounds = true subviewsSpeed = Array() for v in view.subviews{ speed.x += speedVariance.x speed.y += speedVariance.y if !notAnimatableViews.contains(v.tag) { subviewsSpeed.append(speed) } } }