Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CircleView.swift
- import UIKit
- @IBDesignable
- class CircleView: UIView {
- override func drawRect(rect: CGRect) {
- CustomStyleKit.drawCircleView(circleViewColor: UIColor.blueColor(), tLCImage: UIImage(named: "no-photo.png")!, tRCImage: UIImage(named: "no-photo.png")!, bLCImage: UIImage(named: "no-photo.png")!, bRCImage: UIImage(named: "no-photo.png")!, tag: "tag", scale: 1.5)
- }
- override func prepareForInterfaceBuilder() {
- CustomStyleKit.drawCircleView(circleViewColor: UIColor.blueColor(), tLCImage: UIImage(named: "no-photo.png")!, tRCImage: UIImage(named: "no-photo.png")!, bLCImage: UIImage(named: "no-photo.png")!, bRCImage: UIImage(named: "no-photo.png")!, tag: "tag", scale: 1.5)
- }
- }
- //CustomStyleKit.swift
- import UIKit
- public class CustomStyleKit : NSObject {
- //// Drawing Methods
- public class func drawCircleView(#circleViewColor: UIColor, tLCImage: UIImage, tRCImage: UIImage, bLCImage: UIImage, bRCImage: UIImage, tag: String, scale: CGFloat) {
- //// General Declarations
- let context = UIGraphicsGetCurrentContext()
- //// Group
- CGContextSaveGState(context)
- CGContextTranslateCTM(context, 101, 100.5)
- CGContextScaleCTM(context, scale, scale)
- //// OuterCircle Drawing
- CGContextSaveGState(context)
- CGContextTranslateCTM(context, -50, -50)
- CGContextScaleCTM(context, 2, 2)
- var outerCirclePath = UIBezierPath(ovalInRect: CGRectMake(0, 0, 50, 50))
- circleViewColor.setStroke()
- outerCirclePath.lineWidth = 2
- outerCirclePath.stroke()
- CGContextRestoreGState(context)
- //// TextCircle Drawing
- let textCircleRect = CGRectMake(-51, -12, 100, 24)
- var textCirclePath = UIBezierPath(ovalInRect: textCircleRect)
- circleViewColor.setFill()
- textCirclePath.fill()
- let textCircleStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle
- textCircleStyle.alignment = NSTextAlignment.Center
- let textCircleFontAttributes = [NSFontAttributeName: UIFont(name: "Helvetica", size: 9)!, NSForegroundColorAttributeName: UIColor.whiteColor(), NSParagraphStyleAttributeName: textCircleStyle]
- let textCircleTextHeight: CGFloat = NSString(string: tag).boundingRectWithSize(CGSizeMake(textCircleRect.width, CGFloat.infinity), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: textCircleFontAttributes, context: nil).size.height
- CGContextSaveGState(context)
- CGContextClipToRect(context, textCircleRect);
- NSString(string: tag).drawInRect(CGRectMake(textCircleRect.minX, textCircleRect.minY + (textCircleRect.height - textCircleTextHeight) / 2, textCircleRect.width, textCircleTextHeight), withAttributes: textCircleFontAttributes)
- CGContextRestoreGState(context)
- //// TopDivider Drawing
- var topDividerPath = UIBezierPath()
- topDividerPath.moveToPoint(CGPointMake(-0.5, -50.5))
- topDividerPath.addLineToPoint(CGPointMake(-0.5, -11.5))
- topDividerPath.addLineToPoint(CGPointMake(-0.5, -50.5))
- topDividerPath.closePath()
- circleViewColor.setStroke()
- topDividerPath.lineWidth = 3
- topDividerPath.stroke()
- //// BottomDivider Drawing
- var bottomDividerPath = UIBezierPath()
- bottomDividerPath.moveToPoint(CGPointMake(-0.5, 11.5))
- bottomDividerPath.addLineToPoint(CGPointMake(-0.5, 50.5))
- bottomDividerPath.addLineToPoint(CGPointMake(-0.5, 11.5))
- bottomDividerPath.closePath()
- circleViewColor.setStroke()
- bottomDividerPath.lineWidth = 3
- bottomDividerPath.stroke()
- CGContextRestoreGState(context)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement