Created
August 29, 2014 15:30
-
-
Save mchirico/a7cb5c43e7cb4a4554c5 to your computer and use it in GitHub Desktop.
Simple UIView to draw lines and squares
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
import Foundation | |
import UIKit | |
class MyUIV:UIView { | |
//ddrawRect:(CGRect)rect | |
override func drawRect(rect: CGRect) { | |
var ctx = UIGraphicsGetCurrentContext() | |
CGContextClearRect(ctx, rect); | |
let parentViewBounds = self.bounds | |
let parentViewWidth = CGRectGetWidth(parentViewBounds) | |
let parentViewHeight = CGRectGetHeight(parentViewBounds) | |
println ("w,h = \(parentViewWidth),\(parentViewHeight) ") | |
// CGContextClearRect(ctx, rect); | |
CGContextSetRGBFillColor(ctx, 0.0, 1.0, 0.0, 1); // green | |
CGContextFillRect(ctx, CGRectMake(0, 0, parentViewWidth, parentViewHeight)); | |
// println("in drawRect, fractionalHeight = \(fractionalHeight)") | |
var h: CGFloat = 200 // fractionalHeight*parentViewHeight | |
// CGContextSetRGBFillColor(ctx, 1.0, 0.0, 0.0, 1); // red | |
CGContextFillRect(ctx, CGRectMake(0, 0, parentViewWidth, h)) | |
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 0.0, 1); //yellow | |
CGContextFillRect(ctx, CGRectMake(0, 0, 200, 200)) | |
println("in drawRect, h = \(h)") | |
// This works nice | |
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0); // red | |
CGContextMoveToPoint(ctx, 200, 200); | |
CGContextAddLineToPoint(ctx, 0, 0); | |
CGContextAddLineToPoint(ctx, 50, 500); | |
CGContextAddCurveToPoint(ctx, 0.0, 100, 200, 3, 300, 233) | |
CGContextStrokePath(ctx); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment