Created
December 9, 2014 19:59
-
-
Save natecook1000/032d6845f37d16ae5bee to your computer and use it in GitHub Desktop.
ATP T-shirt in Swift
This file contains hidden or 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
| // adadpted from http://atp.fm/t-shirt | |
| import UIKit | |
| class ATPView : UIView { | |
| override func drawRect(rect: CGRect) { | |
| let fontName = "MyriadPro-SemiBold" | |
| let title = NSLocalizedString("Accidental Tech Podcast", comment: "title") | |
| let initials = NSLocalizedString("ATP", comment: "initials") | |
| let rect = CGRect(origin: CGPointZero, size: bounds.size) | |
| let w = rect.width | |
| let offsetY = w * -0.07 | |
| var ringRect = CGRectInset(rect, w * 0.08, w * 0.08) | |
| ringRect.origin.y += offsetY | |
| let ring = UIBezierPath(ovalInRect: ringRect) | |
| ring.lineWidth = ceil(w * 0.012) | |
| UIColor(white: 0.3, alpha: 1.0).setStroke() | |
| ring.stroke() | |
| var innerRingRect = CGRectInset(rect, w * 0.21, w * 0.21) | |
| innerRingRect.origin.y += offsetY | |
| let inner = UIBezierPath(ovalInRect: innerRingRect) | |
| inner.lineWidth = ceil(w * 0.007) | |
| UIColor(white: 0.7, alpha: 1.0).setStroke() | |
| inner.stroke() | |
| let pStyle = NSMutableParagraphStyle() | |
| pStyle.alignment = .Center | |
| let titleAttributes = [ | |
| NSFontAttributeName: UIFont(name: fontName, size: w * 0.068)!, | |
| NSParagraphStyleAttributeName: pStyle, | |
| NSForegroundColorAttributeName: UIColor.whiteColor(), | |
| NSKernAttributeName: w * 0.0037 | |
| ] | |
| let t = title.uppercaseString | |
| let titleRect = CGRectMake(0, w * 0.91, w, w * 0.09) | |
| t.drawWithRect(titleRect, options: .UsesLineFragmentOrigin, attributes: titleAttributes, context: nil) | |
| let bs = CGSize(width: w * 0.44, height: w * 0.19) | |
| let bOrigin = CGPoint(x: (w - bs.width) / 2, y: (w - bs.height) / 2 + offsetY) | |
| let b = CGRect(origin: bOrigin, size: bs) | |
| let (cX, cY) = (CGRectGetMidX(b), CGRectGetMidY(b)) | |
| var transform = CGAffineTransformMakeTranslation(cX, cY) | |
| transform = CGAffineTransformRotate(transform, 0.5236) | |
| transform = CGAffineTransformTranslate(transform, -cX, -cY) | |
| CGContextConcatCTM(UIGraphicsGetCurrentContext(), transform) | |
| UIColor(red: 0.12, green: 0.25, blue: 0.4, alpha: 1.0).setFill() | |
| UIBezierPath(roundedRect: b, cornerRadius: bs.height * 0.15).fill() | |
| var a = titleAttributes | |
| a[NSFontAttributeName] = UIFont(name: fontName, size: bs.height * 0.84)! | |
| a[NSKernAttributeName] = bs.height * 0.04 | |
| let r = CGRectInset(b, 0, bs.height * 0.17) | |
| initials.drawWithRect(r, options: .UsesLineFragmentOrigin, attributes: a, context: nil) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment