How to add Label in BWWalkthrough View Controller with Swift 3?

前端 未结 1 1852
鱼传尺愫
鱼传尺愫 2020-12-22 07:02

I use BWWalkthrough library for slides images in my app. I add Title and Message labels in each slide.


相关标签:
1条回答
  • 2020-12-22 07:26

    Do something like below, that will add one label in all page, you can add more label like same way.

    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)
            }
        }
    }
    

    Update

    You can prevent crash to happening by safe unwrapping lblTitle1 check below.

    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)
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题