Search code examples
ioscustom-controlscalayer

Custom Rounded Button without Corner Radius


how do we subclass a UIbutton and customize it so that it has a round end like this one on Periscope. The Following Button.

I would like to PREVENT using layer.CornerRadius though.

Using a BezierPath perhaps? but I have a math problem creating the Path.

Any thoughts? Thank you

rounded following button


Solution

  • I have created that button using the layer.CornerRadius as below :-

    self.buyButton.layer.cornerRadius = self.buyButton.frame.size.height/2;
    self.buyButton.clipsToBounds = YES;
    

    [UPDATED CODE - FOR SHADOW]

    self.buyButton.layer.masksToBounds = NO;
    
    self.buyButton.layer.borderWidth = 1.0f;    //Just for look n feel
    
    self.buyButton.layer.shadowColor = [UIColor greenColor].CGColor;
    self.buyButton.layer.shadowOpacity = 0.8;
    self.buyButton.layer.shadowRadius = 12;
    self.buyButton.layer.shadowOffset = CGSizeMake(12.0f, 12.0f);
    

    enter image description here

    But why u don't want to use the method already provided as per your custom requirement I don't think you need to use bezier path for this.

    UPDATED SCREENSHOT :

    enter image description here