-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample.swift
47 lines (38 loc) · 1.59 KB
/
Sample.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// Dialogue.swift
// Grimm WatchKit Extension
//
// Created by Tyler Goffinet on 9/26/17.
// Copyright © 2017 Tyler Goffinet. All rights reserved.
//
import WatchKit
class EventRow: NSObject {
// Row colors
let dialogueColor = #colorLiteral(red: 0.4745098039, green: 0.3921568627, blue: 0, alpha: 1)
let responseColor = #colorLiteral(red: 1, green: 0.5764705882, blue: 0, alpha: 1)
let narrationColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
@IBOutlet var group: WKInterfaceGroup!
@IBOutlet var speechLabel: WKInterfaceLabel!
func tailorRow(forExpressionOf expr: Expression) {
var richSpeech: NSAttributedString
switch expr.source {
case .narrator:
richSpeech = getAligned(expr.speech, withAlignment: .left)
group.setBackgroundColor(narrationColor)
case .you:
richSpeech = getAligned(expr.speech, withAlignment: .right)
group.setBackgroundColor(responseColor)
case .them:
richSpeech = getAligned(expr.speech, withAlignment: .left)
group.setBackgroundColor(dialogueColor)
}
speechLabel.setAttributedText(richSpeech)
}
func getAligned(_ text: String, withAlignment alignment: NSTextAlignment) -> NSAttributedString {
let paraStyle = NSMutableParagraphStyle()
paraStyle.alignment = alignment
let richText = NSAttributedString(string: text,
attributes: [NSAttributedStringKey.paragraphStyle: paraStyle])
return richText
}
}