2 // DamageValueTransformer.swift
5 // Created by Hori,Masaki on 2017/01/05.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class DamageValueTransformer: ValueTransformer {
13 override class func transformedValueClass() -> AnyClass {
15 return NSAttributedString.self
18 override func transformedValue(_ value: Any?) -> Any? {
20 guard let v = value as? Int,
21 let type = DamageType(rawValue: v),
22 let attributes = attribute(for: type) else {
27 return NSAttributedString(string: attributes.string, attributes: attributes.attr)
30 private func attribute(for type: DamageType) -> (string: String, attr: [NSAttributedStringKey: Any])? {
38 [.foregroundColor: #colorLiteral(red: 1, green: 0.925, blue: 0, alpha: 1), .paragraphStyle: paragraphStyle]
43 [.foregroundColor: #colorLiteral(red: 1, green: 0.32, blue: 0, alpha: 1), .paragraphStyle: paragraphStyle]
48 [.foregroundColor: #colorLiteral(red: 0.87, green: 0, blue: 0.036, alpha: 1), .paragraphStyle: paragraphStyle]
53 private var paragraphStyle: NSParagraphStyle = {
55 let style = NSMutableParagraphStyle()
56 style.alignment = .center