Skip to content

Instantly share code, notes, and snippets.

@jkopelioff
Created August 27, 2015 18:08
Show Gist options
  • Select an option

  • Save jkopelioff/ba5799d81d759a7ca11a to your computer and use it in GitHub Desktop.

Select an option

Save jkopelioff/ba5799d81d759a7ca11a to your computer and use it in GitHub Desktop.
Rounded UI Button extension
//
// RoundedUIButtion.swift
// eHow
//
// Created by Joel Kopelioff on 4/13/15.
// Copyright (c) 2015 Demand Media. All rights reserved.
//
import UIKit
class RoundedUIButtion: UIButton {
private var corners:UIRectCorner?
private var cornerRadius:CGFloat?
override var bounds: CGRect {
didSet {
if let corners = self.corners, let radius = self.cornerRadius {
self.roundCorners(corners, radius: radius)
}
}
}
func roundCorners(corners:UIRectCorner, radius:CGFloat)
{
self.corners = corners
self.cornerRadius = radius
let rounded:UIBezierPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: self.corners!, cornerRadii: CGSizeMake(radius, radius))
let shape = CAShapeLayer()
shape.path = rounded.CGPath
self.layer.mask = shape
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment