ios - How to make UIImage on setImage UIButton more higher -
what want make uibutton adhere uiview menu when uibutton isselected. black square on uinavigation uiimage after uibutton selected. question how make uiimage (black square) more higher uibutton after selected?
this code on uibutton class .m:
- (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { //...our red stretchy uiimage *redimage = [uiimage imagenamed:@"button_red.png"]; uiimage *redstretchy = [redimage stretchableimagewithleftcapwidth:redimage.size.width / 2 topcapheight:redimage.size.height / 2]; //...initialization code [self setframe:frame]; [self settitle:title forstate:uicontrolstatenormal]; [self setbackgroundimage:redstretchy forstate:uicontrolstatenormal]; [[self titlelabel] setfont:[uifont boldsystemfontofsize:font_size]]; [[self titlelabel] setshadowoffset:cgsizemake(font_shadow_offset, font_shadow_offset)]; //...add target [self addtarget:self action:@selector(actionbutton:) forcontrolevents:uicontroleventtouchupinside]; } return self; }
this target methode:
//...add target - (void)actionbutton:(id)sender { if ([sender isselected]) { } else { cgsize buttonsize = cgsizemake(self.frame.size.width, self.frame.size.height); [sender setimage:[self imagebutton:buttonsize] forstate:uicontrolstateselected]; } if (delegate != nil && [delegate conformstoprotocol:@protocol(buttonprotocol)]) { if ([delegate respondstoselector:@selector(actionbutton:)]) { [delegate performselector:@selector(actionbutton:) withobject:sender]; } } }
and methode create uiimage:
//...create image button - (uiimage *)imagebutton:(cgsize)size { uigraphicsbeginimagecontextwithoptions(size, no, 0); cgcontextref currentcontex = uigraphicsgetcurrentcontext(); cgmutablepathref path = cgpathcreatemutable(); cgrect firstrect = cgrectmake(0.0f, 0.0f, 60.f, 30.0f); cgpathaddrect(path, null, firstrect); cgcontextaddpath(currentcontex, path); uicolor *fillcolor = [uicolor blackcolor]; cgcontextsetfillcolorwithcolor(currentcontex, fillcolor.cgcolor); cgcontextdrawpath(currentcontex, kcgpathfill); uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return image; }
Comments
Post a Comment