import UIKit
class MyCGView: UIView {
override func drawRect(rect: CGRect) {
let context: CGContextRef = UIGraphicsGetCurrentContext()!
CGContextSetRGBFillColor(context,0.0, 1.0, 0.0, 1.0)
CGContextSetLineWidth(context, 5.0)
var r1: CGRect = CGRectMake(20,20,50,50)
CGContextAddRect(context,r1)
CGContextFillPath(context)
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.5, 1.0)
r1 = CGRectMake(30,30,70,70)
CGContextAddRect(context,r1)
CGContextStrokePath(context)
CGContextSetLineWidth(context, 2)
CGContextSetRGBStrokeColor(context, 0, 0, 1, 1)
CGContextMoveToPoint(context, 15, 70)
CGContextAddLineToPoint(context, 280, 200)
CGContextStrokePath(context)
let attrString = NSAttributedString(
string: "漢字abc",
attributes:[NSForegroundColorAttributeName: UIColor.greenColor(),
NSFontAttributeName: UIFont.boldSystemFontOfSize(20.0)])
attrString.drawAtPoint(CGPointMake(40, 70))
}
}
|