Skip to content

Instantly share code, notes, and snippets.

@manchan
Last active August 29, 2015 14:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save manchan/c6eb504fa6155f7715de to your computer and use it in GitHub Desktop.
Swift 丸アイコン内、テキストセンター描画 ref: http://qiita.com/you_matz/items/2e8390a505e7b8a92ec9
// 丸描画
let roundRect = UIBezierPath(roundedRect: CGRectMake(1, 1, 28, 28), cornerRadius: 10)
UIColor.blueColor().setStroke()
roundRect.lineWidth = 2
roundRect.stroke()
// フォント属性
let fontAttr = [NSFontAttributeName: UIFont.systemFontOfSize(10)]
// テキスト
let str = self.initial_txt! as NSString!
// サイズ取得
let size = str.sizeWithAttributes(fontAttr)
let x_pos = (roundRect.bounds.size.width - size.width) / 2
let y_pos = (roundRect.bounds.size.height - size.height) / 2
// テキスト描画
str.drawAtPoint(CGPointMake(roundRect.bounds.origin.x + x_pos, roundRect.bounds.origin.y + y_pos),
withAttributes: fontAttr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment