Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set rectangle border for custom type UIButton

I am trying to set an image as the background of a custom UIButton. I was able to set a background image for the "rounded rect" UIButton in interface builder, but now the borders have vanished. Is there any way to retain the borders? Also, I would like to make the borders show up rectangular instead of rounded.

like image 300
afin Avatar asked May 12 '09 19:05

afin


1 Answers

    #import <QuartzCore/QuartzCore.h> // don't forget to add this in your file
    CALayer * layer = [yourUIButton layer];
    [layer setMasksToBounds:YES];
    [layer setCornerRadius:0.0]; //when radius is 0, the border is a rectangle
    [layer setBorderWidth:1.0];
    [layer setBorderColor:[[UIColor grayColor] CGColor]];

i know this is an old question, but still i would like to post my answer here. since i was looking for answer but got this resolved myself in an easy way.

like image 88
trillions Avatar answered Oct 13 '22 00:10

trillions