Last active
August 29, 2015 14:03
-
-
Save mtrovilho/b3605ddcba3f7d096595 to your computer and use it in GitHub Desktop.
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
// | |
// FlagView.swift | |
// Bandeira Brasil | |
// | |
// Created by Danilo Altheman on 01/07/14. | |
// Copyright (c) 2014 Quaddro. All rights reserved. | |
// | |
import UIKit | |
extension UIColor { | |
convenience init(hex: UInt32) { | |
var r: CGFloat = (CGFloat((hex & 0xFF0000) >> 16) / 255.0) | |
var g: CGFloat = (CGFloat((hex & 0x00FF00) >> 8) / 255.0) | |
var b: CGFloat = (CGFloat (hex & 0x0000FF) / 255.0) | |
self.init(red: r, green: g, blue: b, alpha: 1.0) | |
} | |
} | |
class FlagView: UIView { | |
override func drawRect(rect: CGRect) { | |
// cores | |
let verde = UIColor(hex: 0x00A859) | |
let amarelo = UIColor(hex: 0xFFCC29) | |
let azul = UIColor(hex: 0x3E4095) | |
// dimensões | |
let comprimento: CGFloat = 320 | |
let modulo: CGFloat = comprimento / 20.0 | |
let largura: CGFloat = modulo * 14.0 | |
let meioHorizontal: CGFloat = comprimento / 2.0 | |
let meioVertical: CGFloat = largura / 2.0 | |
let margemLozango: CGFloat = modulo * 1.7 | |
let raioCirculo: CGFloat = modulo * 3.5 | |
let diametroCirculo: CGFloat = raioCirculo * 2.0 | |
let origemCirculo = CGPoint(x: comprimento / 2.0 - raioCirculo, y: largura / 2.0 - raioCirculo) | |
// retangulo | |
let retanguloPath = UIBezierPath(rect: CGRectMake(0, 0, comprimento, largura)) | |
verde.setFill() | |
retanguloPath.fill() | |
// poligono | |
var poligonoPath = UIBezierPath() | |
poligonoPath.moveToPoint(CGPointMake(meioHorizontal, margemLozango)) | |
poligonoPath.addLineToPoint(CGPointMake(comprimento - margemLozango, meioVertical)) | |
poligonoPath.addLineToPoint(CGPointMake(meioHorizontal, largura - margemLozango)) | |
poligonoPath.addLineToPoint(CGPointMake(margemLozango, meioVertical)) | |
poligonoPath.closePath() | |
amarelo.setFill() | |
poligonoPath.fill() | |
// circulo | |
var circuloPath = UIBezierPath(ovalInRect: CGRectMake(origemCirculo.x, origemCirculo.y, diametroCirculo, diametroCirculo)) | |
azul.setFill() | |
circuloPath.fill() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment