Skip to content

Instantly share code, notes, and snippets.

@atljeremy
Created December 30, 2014 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atljeremy/6bf7f38ab0fc754f694c to your computer and use it in GitHub Desktop.
Save atljeremy/6bf7f38ab0fc754f694c to your computer and use it in GitHub Desktop.
Swift UIView Extension for Rounding Views
//
// 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