Created
February 4, 2016 16:42
-
-
Save Athosone/021f0c6c30e88b0a9bec to your computer and use it in GitHub Desktop.
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
// | |
// THTriangleView.swift | |
// thirsty | |
// | |
// Created by Werck Ayrton on 23/06/2015. | |
// Copyright (c) 2015 Nyu Web Developpement. All rights reserved. | |
// | |
import UIKit | |
class THTriangleView: UIView { | |
var color:UIColor? | |
override func drawRect(rect: CGRect) { | |
let context = UIGraphicsGetCurrentContext() | |
drawTriangle(context!, boundedBy: rect, withColor: self.color) | |
} | |
func drawTriangle(context: CGContextRef, boundedBy rect: CGRect, withColor color:UIColor?=nil) | |
{ | |
if let unwrappedColor = color | |
{ | |
CGContextSetFillColorWithColor(context, unwrappedColor.CGColor) | |
} | |
else | |
{ | |
CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor) | |
} | |
CGContextMoveToPoint(context, rect.width / 4, rect.height / 4) | |
CGContextAddLineToPoint(context, rect.width * 3 / 4, rect.height / 2) | |
CGContextAddLineToPoint(context, rect.width / 4, rect.height * 3 / 4) | |
CGContextAddLineToPoint(context, rect.width / 4, rect.height / 4) | |
CGContextFillPath(context) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment