Skip to content

Instantly share code, notes, and snippets.

@Athosone
Created February 4, 2016 16:42
Show Gist options
  • Save Athosone/021f0c6c30e88b0a9bec to your computer and use it in GitHub Desktop.
Save Athosone/021f0c6c30e88b0a9bec to your computer and use it in GitHub Desktop.
//
// 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