Rounded Corners only on Top of a UIView

You can do this by setting a mask on your view’s layer: CAShapeLayer * maskLayer = [CAShapeLayer layer]; maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: (CGSize){10.0, 10.}].CGPath; self.layer.mask = maskLayer; IMPORTANT: You should do this in your view’s layoutSubviews() method, so the view has already been resized from the storyboard In Swift … Read more

Rounded Button in Android

You can do a rounded corner button without resorting to an ImageView. A background selector resource, button_background.xml: <?xml version=”1.0″ encoding=”utf-8″ ?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– Non focused states –> <item android:state_focused=”false” android:state_selected=”false” android:state_pressed=”false” android:drawable=”@drawable/button_unfocused” /> <item android:state_focused=”false” android:state_selected=”true” android:state_pressed=”false” android:drawable=”@drawable/button_unfocused” /> <!– Focused states –> <item android:state_focused=”true” android:state_selected=”false” android:state_pressed=”false” android:drawable=”@drawable/button_focus” /> <item android:state_focused=”true” android:state_selected=”true” android:state_pressed=”false” android:drawable=”@drawable/button_focus” … Read more

How to put rounded corners on a Chart.js Bar chart

As pointed out in https://stackoverflow.com/a/68778432/360067, this is natively implemented in v3. Original Answer Here is how you extend Chart.js to draw a bar chart with rounded corners. Chart.types.Bar.extend({ name: “BarAlt”, initialize: function (data) { Chart.types.Bar.prototype.initialize.apply(this, arguments); if (this.options.curvature !== undefined && this.options.curvature <= 1) { var rectangleDraw = this.datasets[0].bars[0].draw; var self = this; var radius … Read more

Just two rounded corners? [duplicate]

In Objective C // Create the path (with only the top-left corner rounded) UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = imageView.bounds; maskLayer.path = maskPath.CGPath; // Set the newly created shape layer as the mask for the image … Read more

Rounded edges in button C# (WinForms)

This is a quick one, you may want to fine tune things and optimize quite a few details.. class RoundedButton : Button { GraphicsPath GetRoundPath(RectangleF Rect, int radius) { float r2 = radius / 2f; GraphicsPath GraphPath = new GraphicsPath(); GraphPath.AddArc(Rect.X, Rect.Y, radius, radius, 180, 90); GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width – r2, Rect.Y); GraphPath.AddArc(Rect.X … Read more

Round Top Corners of a UIButton in Swift

Swift 4: For latest iOS 11 onwards override func viewDidLoad() { super.viewDidLoad() if #available(iOS 11.0, *) { self.viewToRound.clipsToBounds = true viewToRound.layer.cornerRadius = 20 viewToRound.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] } else { // Fallback on earlier versions } } Earlier iOS (10,9 etc) Versions (works for iOS 11 too) override func viewDidLayoutSubviews() { self.viewToRound.clipsToBounds = true let … Read more

ImageView rounded corners [duplicate]

SIMPLEST APPROACH: Create an xml file rounded_fg.xml under res/drawable/ folder of your app. The content of rounded_fg.xml is as follows, <?xml version=”1.0″ encoding=”UTF-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:innerRadiusRatio=”2″ android:shape=”ring” android:thicknessRatio=”1″ android:useLevel=”false”> <gradient android:type=”radial” android:gradientRadius=”8dp” android:endColor=”@color/white” /> </shape> You can match endColor with ImageView container layout background & gradientRadius may be any value as per your requirements (<=36dp). … Read more

How to set layer cornerRadius for only bottom-left, bottom-right, and top-left corner?

(swift 4/iOS 11) Just simply say for bottom: yourView.clipsToBounds = true yourView.layer.cornerRadius = 10 yourView.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMinXMaxYCorner] for Up: yourView.clipsToBounds = true yourView.layer.cornerRadius = 10 yourView.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner] in your case: yourView.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMinXMaxYCorner, .layerMinXMinYCorner] Hope this help 🙂