How to remove sharp edges of a rectangle from a UIButton control?

Take a look at the following image:

enter image description here

As you can see, the edges are a sharp rectangle and they come out of a rounded corner button. How can I not show the edges and show only the round button?

UPDATE (decision):

I used the following code to achieve round corners:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.stopButton.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(12.0, 12.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = self.stopButton.bounds; maskLayer.path = maskPath.CGPath; // Set the newly created shape layer as the mask for the image view layer self.stopButton.layer.mask = maskLayer; 

NEW CHALLENGE:

This code gives me an error in the line startButtonRound.layer.cornerRadius.

  UIButton *roundStartButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; roundStartButton.frame = CGRectMake(10, 10, 100, 20); [roundStartButton setBackgroundImage:[UIImage imageNamed:@"green_gradient.jpg"] forState:UIControlStateNormal]; roundStartButton.layer.cornerRadius = 12.0; UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithCustomView:roundStartButton]; 
+8
ios xcode4
source share
3 answers

You can only do this with CALayer:

 CALayer *myLayer = [CALayer layer]; [myLayer setMasksToBounds:YES]; [myLayer setCornerRadius:5.0f]; [myLayer setBorderWidth:1.0f]; [myLayer setBorderColor: [[UIColor blackColor] CGColor]]; [myLayer setBackgroundColor: [[UIColor whiteColor] CGColor]]; 

You will also want to enable the QuartzCore environment and include the framework title in your own.

 #include <QuartzCore/QuartzCore.h> 

Hope this helps

Tim

+17
source share

I think that everything that can be achieved with:

 self.stopButton.layer.cornerRadius = 12.0; 

But have you tried

 self.stopButton.opaque = NO; self.stopButton.backgroundColor = [UIColor clearColor]; 

?

+5
source share

shape the look of the image that you set for the UButton bckground color to White. Make it "Clear Color."

0
source share

All Articles