Make selective UIView corners rounded:
Make selective UIView corners rounded
suggest changeFirst import #import <QuartzCore/QuartzCore.h> into your ViewController class. Here is how I set my view in code
UIView *view1=[[UIView alloc]init];
view1.backgroundColor=[UIColor colorWithRed:255/255.0 green:193/255.0 blue:72/255.0 alpha:1.0];
CGRect view1Frame = view1.frame;
view1Frame.size.width = SCREEN_WIDTH*0.97;
view1Frame.size.height = SCREEN_HEIGHT*0.2158;
view1Frame.origin.x = 0;
view1Frame.origin.y = 0.1422*SCREEN_HEIGHT-10;
view1.frame = view1Frame;
[self setMaskTo:view1 byRoundingCorners:UIRectCornerBottomRight|UIRectCornerTopRight];
[self.view addSubview:view1];
Here is the function which does the heavy lifting and rounds off the selected edges which is the Bottom Right and the Top Right edge in our case
- (void)setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners
{
UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(20.0, 20.0)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
view.layer.mask = shape;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents
12UIView
15UIColor
26UIImage
28CALayer
30NSDate
40iBeacon
43UISwitch
49NSTimer
69Fastlane
79NSURL
87AWS SDK
91UIDevice
92CloudKit
96NSData
101Segues
102UIDatePicker
103NSPredicate
104EventKit
105NSBundle
106SiriKit
111StoreKit
112Code signing
1173D Touch
119Keychain
122Block
130Make selective UIView corners rounded
141AirDrop
144UISlider
145Carthage
146HealthKit
148UI Testing
149Core Motion
151plist
152NSInvocation
155AppDelegate
157MVVM
158UIStoryboard
161MPVolumeView
164UIPhoenix
166Simulator
168NSArray
169OpenGL
175Core Data
179MyLayout
180UIFont
189Security
200Codable
201FileHandle
210Contributors