LoginSignup
17
17

More than 5 years have passed since last update.

[Swift] 数値を画像に変換するライブラリを書いた

Last updated at Posted at 2016-02-02

とてもニッチですが、必要に迫られたので作りました。
https://github.com/taketin/DieCast

使い方

README に書いていますが、Carthage もしくは CocoaPods で入ります。

import DieCast して、以下のようなコードを書くと

if let diecast = DieCast(material: 1234567890) {
    let diecastView = diecast.press()
    view.addSubview(diecastView)
}

スクリーンショット 2016-02-01 23.56.02.png

こんな感じで、数字が画像に変換されます。
今のところ用意している画像はスクショの1種類しかありませんが、以下の様に独自の画像を設定できます。

if let diecast = DieCast(material: 1234567890, type: IntCast.Custom, filenamePrefix: "your_image_prefix_") {
    let diecastView = diecast.press()
    view.addSubview(diecastView)
}

独自の画像を使用する際は、ファイル名を your_image_prefix_[0-9].png みたいにして、0 から 9 までの数字画像を用意して、Asset Catalog で利用してください。

リポジトリに Demo App が入っていますのでそちらもご覧ください。

オプション

  • もと画像サイズへの倍率、または height によるサイズの指定
  • 画像間のマージン

が以下の様に設定できます。

if let diecast = DieCast(material: 1234567890) {
    // 倍率による指定
    diecast.magnification = 0.06

    // 高さによる指定 (magnification が設定されている場合はそちらが優先されます)
    diecast.height = 30.0

    // 画像間のマージン指定
    diecast.margin = 5.0

    let diecastView = diecast.press()
    view.addSubview(diecastView)
}

おわりに

ニーズがあると嬉しいです :smiley:

17
17
2

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