UIToolbar with rounded corners

I want to display a UIToolbar with rounded corners on top, which would be the easiest way? the toolbar is not aligned to the top of the window; he has stock in all directions. Thanks!

+7
iphone uitoolbar
source share
2 answers

Very simple.

First of all, I have the UIToolbar IBOutlet variable in your .h file of your controller. For example.

 @interface TextFormattedViewController : UIViewController { IBOutlet UIToolbar *tBar; } 

Now, in your .m file of your view controller file, just put the following code and it will work like magic for you. However, please add a comment if any queries.

 #import "TextFormattedViewController.h" #import <QuartzCore/QuartzCore.h> @implementation TextFormattedViewController - (void)viewDidLoad { // following statement is must. tBar.clipsToBounds=YES; CALayer *l=tBar.layer; // set corner radious [l setCornerRadius:10]; // to apply border on corners [l setBorderColor:[[UIColor redColor] CGColor]]; // to apply set border width. [l setBorderWidth:5.0]; } 
+16
source share

The easiest way to round view angles is cornerRadius (and masksToBounds ) CALayer . However, at the same time you have the opportunity to round all corners the same. To use this property, you can put the UIToolbar in another view that was taller than the toolbar, so only the top was rounded. This will work well if the other view has rounded bottom corners.

The easiest way to mask a free-form view is to set the mask CALayer property to the new CAShapeLayer . In your case, create a CGPath for CAShapeLayer using CGPathAddLineToPoint and CGPathAddArcToPoint or similar to round only the top corners.

+2
source share

All Articles