Last active
August 29, 2015 14:12
-
-
Save JigarM/356916b6c840cd7ed5e1 to your computer and use it in GitHub Desktop.
Rounded Only three Corners of a UIView
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
#import <UIKit/UIKit.h> | |
@interface ViewController : UIViewController | |
@property (weak, nonatomic) IBOutlet UIView *profile; //(264, 134, 100, 100) | |
@property (weak, nonatomic) IBOutlet UIView *subview; //(0, 5, 95, 95) : This view added in profile view | |
@end |
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
#import "ViewController.h" | |
#define CORNER_RADIUS 32 | |
#define SUBVIEW_CORNER_RADIUS 25 | |
//@property (weak, nonatomic) IBOutlet UIView *profile; (264, 134, 100, 100) | |
//@property (weak, nonatomic) IBOutlet UIView *subview; (0, 5, 95, 95) : This view added in profile view | |
@implementation ViewController | |
@synthesize profile, subview; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
UIGraphicsBeginImageContext(self.view.frame.size); | |
[[UIImage imageNamed:@"defaultnoprofilepic.jpg"] drawInRect:self.subview.bounds]; | |
UIImage *profilePic = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
CAShapeLayer *maskLayer = [CAShapeLayer layer]; | |
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.profile.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerBottomRight| UIRectCornerBottomLeft cornerRadii:(CGSize){CORNER_RADIUS, CORNER_RADIUS}].CGPath; | |
self.profile.layer.mask = maskLayer; | |
CAShapeLayer *maskLayer1 = [CAShapeLayer layer]; | |
maskLayer1.path = [UIBezierPath bezierPathWithRoundedRect:self.subview.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerBottomRight| UIRectCornerBottomLeft cornerRadii:(CGSize){SUBVIEW_CORNER_RADIUS, SUBVIEW_CORNER_RADIUS}].CGPath; | |
self.subview.layer.mask = maskLayer1; | |
[self.subview setBackgroundColor:[UIColor colorWithPatternImage:profilePic]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment