Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is a working SWIFT example: Auto change text with timer #20

Open
wy1024 opened this issue Aug 18, 2017 · 2 comments
Open

Here is a working SWIFT example: Auto change text with timer #20

wy1024 opened this issue Aug 18, 2017 · 2 comments

Comments

@wy1024
Copy link

wy1024 commented Aug 18, 2017

Just wanted to put it out there in case anyone needs it. Here is a swift controller, and changes the text itself with a timer.

//
// IntroViewController.swift
//
// Created by Jason wang on 8/16/17.
//

import Foundation
import UIKit
import RQShineLabel
import Parse

class IntroViewController: UIViewController {
var shineLabel = RQShineLabel()
var timer = Timer()
var textArray = ["111", "222", "333"]
var currentCount = 0

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    
    self.shineLabel.shine()
}

var background1 = UIImageView()
var background2 = UIImageView()

override func viewDidLoad() {
    super.viewDidLoad()
    
    background1 = UIImageView(image: UIImage(named: "IntroBackground1")!)
    background1.contentMode = .scaleAspectFill
    background1.frame = self.view.bounds
    self.view.addSubview(background1)
    
    background2 = UIImageView(image: UIImage(named: "IntroBackground2")!)
    background2.contentMode = .scaleAspectFill
    background2.frame = self.view.bounds
    background2.alpha = 0
    self.view.addSubview(background2)
    
    self.shineLabel = RQShineLabel(frame: CGRect(x: 16, y: 16, width: 298, height: 300))
    self.shineLabel.numberOfLines = 0;
    self.shineLabel.text = "Welcome to my app"
    self.shineLabel.backgroundColor = UIColor.clear
    self.shineLabel.font = UIFont(name: "HelveticaNeue-Light", size: 18.0)
    self.shineLabel.center = self.view.center;
    self.view.addSubview(self.shineLabel)
    
    scheduledTimerWithTimeInterval()

    self.view.bringSubview(toFront: self.logo)
    self.view.bringSubview(toFront: self.loginView)
}

func scheduledTimerWithTimeInterval(){
    // Scheduling timer to Call the function "updateCounting" with the interval of 1 seconds
    timer = Timer.scheduledTimer(timeInterval: 8, target: self, selector: #selector(self.updateCounting), userInfo: nil, repeats: true)
}

func updateCounting(){
    if (self.shineLabel.isVisible) {
        self.shineLabel.fadeOut(completion: {
            let textIndex = self.currentCount % self.textArray.count
            let text = self.textArray[textIndex]
            self.shineLabel.text = text
            self.currentCount += 1
            UIView.animate(withDuration: 2.5, animations: {
                if (self.background1.alpha > 0.1) {
                    self.background1.alpha = 0;
                    self.background2.alpha = 1;
                }
                else {
                    self.background1.alpha = 1;
                    self.background2.alpha = 0;
                }
            })
            self.shineLabel.shine()
        })
    } else {
        self.shineLabel.shine()
    }
    
}

}

@MarinaHuber
Copy link

Hi there, could this be used with storyboard instead programmatic Label?

@dkk
Copy link

dkk commented Nov 15, 2019

RQShineLabel inherits from UILabel. Just add it as a label in IB and set the class to RQShineLabel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@dkk @wy1024 @MarinaHuber and others