Skip to content

Instantly share code, notes, and snippets.

@manchan
Created November 25, 2014 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manchan/1e9cfae322f87583a2f7 to your computer and use it in GitHub Desktop.
Save manchan/1e9cfae322f87583a2f7 to your computer and use it in GitHub Desktop.
AppleWatch Tutorial Emoji Zoom
//
// EmojiRow.swift
// EmojiWatch
//
// Created by matz on 2014/11/24.
// Copyright (c) 2014年 matz. All rights reserved.
//
import UIKit
import WatchKit
class EmojiRow: NSObject {
@IBOutlet weak var emojiRowLabel: WKInterfaceLabel!
}
//
// InterfaceController.swift
// EmojiWatch WatchKit Extension
//
// Created by matz on 2014/11/24.
// Copyright (c) 2014年 matz. All rights reserved.
//
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var table: WKInterfaceTable!
var emojis:[[String]] =
[
["Fall in love","😍"],
["Innocent","😇"],
["Pig","🐷"],
["Ghost","👻"],
["Beer","🍺"],
["Humster","🐹"]
]
override init(context: AnyObject?) {
// Initialize variables here.
super.init(context: context)
self.table.setNumberOfRows(self.emojis.count, withRowType: "EmojiRow")
for index in 0..<self.emojis.count {
var theRow = self.table.rowControllerAtIndex(index) as EmojiRow
theRow.emojiRowLabel.setText(self.emojis[index][1])
}
}
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
self.pushControllerWithName("ZoomEmojiController", context: self.emojis[rowIndex])
}
}
//
// ZoomEmojiController.swift
// EmojiWatch
//
// Created by matz on 2014/11/24.
// Copyright (c) 2014年 matz. All rights reserved.
//
import UIKit
import WatchKit
class ZoomEmojiController: WKInterfaceController {
@IBOutlet weak var zoomEmojiLabel: WKInterfaceLabel!
@IBOutlet weak var definitionLabel: WKInterfaceLabel!
override init(context: AnyObject?) {
// Initialize variables here.
super.init(context: context)
var emoji:AnyObject = context!
// Emoji Zoom size
var font = UIFont.systemFontOfSize(90)
var specialString = NSAttributedString(string: emoji[1] as String, attributes: [NSFontAttributeName:font])
self.zoomEmojiLabel.setAttributedText(specialString)
var definition = emoji[0] as String
self.definitionLabel.setText(definition)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment