/
InterfaceController.swift
37 lines (28 loc) · 1.34 KB
/
InterfaceController.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
//
// InterfaceController.swift
// WatchKitSettingsBundle WatchKit Extension
//
// Created by Patrick Balestra on 09/02/15.
// Copyright (c) 2015 Patrick Balestra. All rights reserved.
//
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var label: WKInterfaceLabel!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
loadFontSize()
NotificationCenter.default.addObserver(self, selector: #selector(InterfaceController.loadFontSize), name: UserDefaults.didChangeNotification, object: nil)
}
override func didDeactivate() {
NotificationCenter.default.removeObserver(self)
}
@objc func loadFontSize() {
let preferencesUserDefaults = UserDefaults(suiteName: "group.patrickbalestra.watchkitsettingsbundle.preferences")
if (preferencesUserDefaults?.value(forKey: "fontSize") as? String) != nil {
let fontSize = CGFloat((preferencesUserDefaults?.value(forKey: "fontSize") as! NSString).floatValue)
let attributedString = NSAttributedString(string: "This is a label example with a font size of \(fontSize).", attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: fontSize)])
label.setAttributedText(attributedString)
}
}
}