Created
December 30, 2014 17:03
-
-
Save atljeremy/6bf7f38ab0fc754f694c to your computer and use it in GitHub Desktop.
Swift UIView Extension for Rounding Views
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
// | |
// UIView.swift | |
// Kidsay | |
// | |
// Created by Jeremy Fox on 12/19/14. | |
// Copyright (c) 2014 Jeremy Fox. All rights reserved. | |
// | |
import UIKit | |
extension UIView { | |
func makeRound() { | |
self.contentMode = .ScaleAspectFill; | |
self.clipsToBounds = true; | |
var f = self.frame; | |
var w = CGRectGetWidth(f); | |
var h = CGRectGetHeight(f); | |
var corner = w; | |
if (h > w) { // Portrait Orientation | |
f.size.height = w; | |
} else if (w > h) { // Landscape Orientation | |
f.size.width = h; | |
corner = h; | |
} | |
self.frame = f; | |
self.layer.cornerRadius = (corner / 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment