How to remove sharp rectangle edges from UIButton control?

Viewed 7683

Take a look at the following image:

enter image description here

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

UPDATE (Solution):

I used the following code to achieve the 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's layer
self.stopButton.layer.mask = maskLayer;

NEW PROBLEM:

This code gives me the error on the startButtonRound.layer.cornerRadius line.

  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];
3 Answers
Related