LoginSignup
2
1

More than 5 years have passed since last update.

Core Graphicsで文字列を中央寄せにする

Last updated at Posted at 2016-10-11

スクリーンショット_2016_10_11_16_19.png

文字列のスタイルを変更するには、

  1. デフォルトのスタイルのコピーを取って、
  2. そのプロパティを変更し、
  3. 適用する。
title = "title"

//ダメ let style = NSMutableParagraphStyle.defaultParagraphStyle()

let textStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle
    textStyle.alignment = NSTextAlignment.Center
    let textFontAttributes = [
        NSParagraphStyleAttributeName: textStyle
    ]

let textRect = CGRectMake(0, 0, 20, 10)
title.drawInRect(textRect, withAttributes: textFontAttributes)

ブログやっています:http://weed.nagoya

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1