ios - UIImageView round border with margin -
i'm using code create rounder uiimageview:
-(void) makeimageviewrounded { self.layer.backgroundcolor=[[uicolor greencolor] cgcolor]; self.layer.cornerradius= self.frame.size.height /2; self.clipstobounds = yes; self.layer.maskstobounds = yes; self.layer.borderwidth=1.5; self.layer.bordercolor=[[uicolor graycolor] cgcolor]; }
this outcome (ignore background if jpg.. starts rounded border):
i want create margin between image , rounded border outcome (ignore background if jpg.. starts rounded border):
how can achieve ?
i figured way, make uiview subclass called circleview, in implementation, add
- (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code [self setbackgroundcolor:[uicolor clearcolor]]; } return self; } - (void)drawrect:(cgrect)rect { cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetlinewidth(context, 20.0); cgcontextsetstrokecolorwithcolor(context, [uicolor lightgraycolor].cgcolor); cgrect rectangle = self.bounds; cgfloat linewidth = self.superview.layer.borderwidth; rectangle = cgrectinset(rectangle, linewidth, linewidth); cgcontextaddellipseinrect(context, rectangle); cgcontextstrokepath(context); } //then add circle view imageview circleview *circle = [[circleview alloc]initwithframe:imageview.bounds]; [imageview addsubview:circle];
Comments
Post a Comment