LoginSignup
17
17

More than 5 years have passed since last update.

LTMorphingLabel使ってみた

Last updated at Posted at 2015-04-29

Textに出力している文字に動きをつける

LTMorphingLabel

Labelなどに出力している文字をオサレな感じに出力します。

.Scale - default

LTMorphingLabel

.Evaporate

LTMorphingLabel-Evaporate

.Fall

LTMorphingLabel-Fall

.Pixelate

LTMorphingLabel-Pixelate

.Sparkle

LTMorphingLabel-Sparkle

.Burn

LTMorphingLabel-Burn

.Anvil

LTMorphingLabel-Anvil

環境(Requirements)

  1. Xcode 6.3
  2. iOS 8.0+

導入

cocoaPodでインストールが上手くいかないので
手動でプロジェクトに導入します。

インストール

LTMorphingLabelからダウンロード後
LTMorphingLabelフォルダをプロジェクトに追加。
追加する際に

スクリーンショット 2015-04-29 16.31.22.png

Added foldersをCreate groupsにチェックしFinishを押す。

Labelの設定

スクリーンショット 2015-04-29 16.56.31.png

Classには、LTMorphingLabelを選択

ViewController

使いたいViewControllerに,デリゲートプロトコル宣言

ViewController.swift
class ViewController: UIViewController, LTMorphingLabelDelegate{
ViewController.swift
    var textArray = [
        "iPhone",
        "iPad",
        "iPod"
    ]

    var i = 0

    var text:String {
        get {
            if i >= textArray.count {
                i = 0
            }
            return textArray[i++]
        }
    }

表示させたい文字を配列へ格納し、textが配列の個数まで来たらリセットを行うことでループして表示

    @IBOutlet var label: LTMorphingLabel!

    @IBAction func changeText(sender: AnyObject) {
        label.text = text
    }

    @IBAction func segmentChanged(sender: UISegmentedControl) {
        let seg = sender
        switch seg.selectedSegmentIndex {
        case 1:
            self.label.morphingEffect = .Evaporate
        case 2:
            self.label.morphingEffect = .Fall
        case 3:
            self.label.morphingEffect = .Pixelate
        case 4:
            self.label.morphingEffect = .Sparkle
        default:
            self.label.morphingEffect = .Scale
        }
        self.changeText(sender);
    }

今回は、SegmentControllerで選択すると、Effectが出力されself.changeText(sender)で、アクションの値を渡しています。

これで、オサレなエフェクトが使えます。

17
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17