Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active July 11, 2016 16:15
Show Gist options
  • Save KentarouKanno/42b31f50dbca4febe57e74d2d24f98a9 to your computer and use it in GitHub Desktop.
Save KentarouKanno/42b31f50dbca4febe57e74d2d24f98a9 to your computer and use it in GitHub Desktop.
TTTAttributedLabel

TTTAttributedLabel

TTTAttributedLabel/TTTAttributedLabel

pod 'TTTAttributedLabel'

★ 縦書きサンプル

import UIKit
import TTTAttributedLabel

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myLabel: TTTAttributedLabel = TTTAttributedLabel(frame: CGRect(x: 0, y: 80, width: 320, height: 320))
        myLabel.backgroundColor = UIColor.whiteColor()
        view.addSubview(myLabel)
        
        myLabel.textColor = UIColor.blackColor()
        myLabel.numberOfLines = 0
        myLabel.font = UIFont.systemFontOfSize(20)
        myLabel.verticalAlignment = .Top
        
        let angle = M_PI/2
        
        myLabel.transform = CGAffineTransformMakeRotation(CGFloat(angle))
        
        let text = "国境の長いトンネルを抜けると雪国であった。夜の底が白くなった。信号所に汽車が止まった。\n向側の座席から娘が立って来て、島村の前のガラス窓を落した。雪の冷気が流れこんだ。娘は窓いっぱいに乗り出して、遠くへ叫ぶように、\n「駅長さあん、駅長さあん。」\n明りをさげてゆっくり雪を踏んで来た男は、襟巻で鼻の上まで包み、耳に帽子の毛皮を垂れていた。"
        
        myLabel.setText(text) { (mutableAttributedString) -> NSMutableAttributedString! in
            
            mutableAttributedString.addAttribute(kCTVerticalFormsAttributeName as String, value: true, range: NSMakeRange(0,mutableAttributedString.length))
            return mutableAttributedString
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment