Swift 丸アイコン内、テキストセンター描画 ref: http://qiita.com/you_matz/items/2e8390a505e7b8a92ec9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 丸描画 | |
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