Skip to content

Instantly share code, notes, and snippets.

@akisute
Created August 17, 2016 07:35
Show Gist options
  • Save akisute/a886d49636756865b344383f3e4ff38a to your computer and use it in GitHub Desktop.
Save akisute/a886d49636756865b344383f3e4ff38a to your computer and use it in GitHub Desktop.
Font Tester Playground. You can learn how text is drawn and affected by various settings.
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
// To continue running NSURLSession async download, make this playground page keep running
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let font = UIFont.systemFontOfSize(16.0)
//let font = UIFont(name: "HiraKakuProN-W3", size: 16.0)!
//let sampleString = "The quick brown fox jumps over a brown dog"
let sampleString = "吾輩はjcbである。名前はxyz。"
//let sampleString = "吾輩は猫である。名前はまだない。"
var s = NSMutableParagraphStyle()
let attributes: [String: AnyObject] = [NSFontAttributeName: font, NSParagraphStyleAttributeName: s]
let attributedString = NSAttributedString(string: sampleString, attributes: attributes)
let label = UILabel()
label.backgroundColor = UIColor.cyanColor()
label.attributedText = attributedString
label.sizeToFit()
let view = UIView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))
view.backgroundColor = UIColor.whiteColor()
view.addSubview(label)
XCPlaygroundPage.currentPage.liveView = view
print("font pointSize=\(font.pointSize)")
print("font lineHeight=\(font.lineHeight)")
print("font ascender=\(font.ascender)")
print("font capHeight=\(font.capHeight)")
print("font descender=\(font.descender)")
print("font leading=\(font.leading)")
print("attributed string=\(attributedString)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment