Monday, 15 April 2013

objective c - Make button's foreground image start from bottom -



objective c - Make button's foreground image start from bottom -

iterate through date cells , set each cell's foreground image dynamically

for (int = 0; < numdatesselected; i++) { uibutton *mybutton = (uibutton *)[self.smallcalendarview viewwithtag:[selecteddates[i] timeintervalsince1970]]; float btnwidth = mybutton.frame.size.width; float btnheight = (mybutton.frame.size.height - (i*3)); uiimage *img = [self imagewithcolor:[uicolor greencolor] width:btnwidth height:btnheight]; [mybutton setimage:img forstate:uicontrolstatenormal]; }

}

return uiimage objects

- (uiimage *)imagewithcolor:(uicolor *)color width:(float)w height:(float)h { cgrect rect = cgrectmake(0, 0, w, h); // create w h pixel context uigraphicsbeginimagecontextwithoptions(rect.size, no, 0); [color setfill]; uirectfill(rect); // fill color uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); homecoming image; }

the result this

i want place greenish boxes @ bottom of each table cell. vertically centered. how do it? give thanks you!!

i suggest creating images of same size button , filling inner rect placed want.

- (uiimage *)imagewithcolor:(uicolor *)color totalwidth:(float)tw totalheight:(float)th filledwidth:(float)fw filledheight:(float)fh { cgrect rect = cgrectmake(0, 0, tw, th); // create tw th pixel context uigraphicsbeginimagecontextwithoptions(rect.size, no, 0); //create inner rect fill color cgrect innerrect = cgrectmake(0 , th - fh, fw, fh); [color setfill]; // fill inner rect color uirectfill(innerrect); uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); homecoming image; }

objective-c

No comments:

Post a Comment