Skip to content

Instantly share code, notes, and snippets.

View osfalt's full-sized avatar

Andrey S osfalt

  • Trainline
  • London, UK
View GitHub Profile
@osfalt
osfalt / UIImage+CornerRadius.m
Created February 12, 2019 19:38
Image with corner radius without Offscreen rendering
@implementation UIImage (CornerRadius)
- (UIImage *)imageWithCornerRadius:(CGFloat)radius andSize:(CGSize)size {
CGRect rect = {0.f, 0.f, size};
UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextAddPath(currentContext, path.CGPath);