Skip to content

Instantly share code, notes, and snippets.

@ginrou
Last active December 30, 2015 09:29
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 ginrou/7809580 to your computer and use it in GitHub Desktop.
Save ginrou/7809580 to your computer and use it in GitHub Desktop.
UIImageViewを円形にマスクをかける
#import <UIKit/UIKit.h>
@interface UIImageView (CircleMask)
- (void)circleMask;
- (void)circleMaskBorderWitdh:(CGFloat)width color:(CGColorRef)color;
@end
@import QuartzCore;
#import "UIImageView+CircleMask.h"
@implementation UIImageView (CircleMask)
- (void)circleMask {
CALayer *layer = self.layer;
layer.cornerRadius = MAX(self.frame.size.width, self.frame.size.height) / 2.0;
layer.masksToBounds = YES;
}
- (void)circleMaskBorderWitdh:(CGFloat)width color:(CGColorRef)color {
[self circleMask];
self.layer.borderWidth = width;
self.layer.borderColor = color;
}
@end
@ginrou
Copy link
Author

ginrou commented Dec 5, 2013

how to use

import header file

#import "UIImageView+CircleMask.h"

set mask as

[imageView circleMask];

or with radius and color

[imageView circleMaskBorderWitdh:2.0 color:[[UIColor whiteColor] CGColor]];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment