1, the color of the pure color map with a picture
Thin Body Code
-(UIImage *) Imagecolordraw: (Uicolor *) color{cgsize size = self.size; CGFloat scale = [Osconfigservice sharedinstance].screenscale; Cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb (); Cgcontextref context = Cgbitmapcontextcreate (NULL, Size.width * scale, Size.height*scale,8,4* Size.width * scale, colorspace,cg_image_alpha_premultiplied_last); Cgcontextsetfillcolorwithcolor (context, color. Cgcolor); Cgmutablepathref path = cgpathcreatemutable (); CGRect rect = CGRectMake (0,0, Size.width * scale, size.height * scale); Cgcontextcliptomask (context, rect, self.) Cgimage); Cgpathaddrect (Path, NULL, rect); Cgcontextaddpath (context, path); Cgcontextfillpath (context); Cgpathrelease (path); Cgcontextstrokepath (context); Cgimageref Imageref = cgbitmapcontextcreateimage (context); UIImage *newimage = [UIImage imagewithcgimage:imageref scale:scale Orientation:uiimageorientationup]; Cgimagerelease (IMAGEREF); Cgcolorspacerelease (ColorSpace); Cgcontextrelease (context);returnNewImage;} Rightbutton = [UIButton buttonwithtype:uibuttontypecustom]; [Rightbutton setimage:[uiimage imagenamed:@"Shelf_navigationbar_search.png"] Forstate:uicontrolstatenormal]; [Rightbutton setimage:[[uiimage imagenamed:@"Shelf_navigationbar_search.png"] Imagecolordraw:rgb (245,173,156)] [forstate:uicontrolstatehighlighted]; [Rightbutton addtarget:self Action:@selector(onrightbuttonclicked:) forcontrolevents:uicontroleventtouchupinside]; [Rightbutton SizeToFit]; Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] Initwithcustomview:rightbutton];returnBackbutton;
2, picture control size varies, with a default diagram
Thin Body Code
Self.contentmode = Uiviewcontentmodecenter; Self.backgroundcolor = [Uicolor colorwithhex:0xf8f8f8]; Self.image = [UIImage imagenamed:@"Defaultimage.png"];__weak typeof(self) weakself= self; [Self setimagewithurlstring:urlstring block:^ (UIImage *image) {if(image) {weakself.contentmode = Uiviewcontentmodescaletofill; Weakself.backgroundcolor = [Uicolor Whitecolor]; Weakself.image = image; } }];
3. Button press to change background without picture
Thin Body Code
#Import "TBRBaseButton.h"@interfaceTbrbasebutton ()@property(Nonatomic, Strong) Nsmutabledictionary *backgrounds;@end@implementationtbrbasebutton-(nsmutabledictionary *) backgrounds{if(_backgrounds = = Nil) {_backgrounds = [Nsmutabledictionary dictionary]; }return _backgrounds;} - (void) dealloc{RELEASE (_backgrounds);} - (void) SetBackgroundColor: (Uicolor *) color forstate: (uicontrolstate) state{[self.backgrounds setobject:color forKey:[ NSNumber Numberwithint:state]];if(!self.backgroundcolor | | state = = uicontrolstatenormal) {self.backgroundcolor = color; }}- (void) Setbackgroundtocolor: (NSNumber *) key{uicolor *background = [Self.backgrounds Objectforkey:key];if(Kind_of_classe (background, uicolor)) {[UIView animatewithduration:0.1fanimations:^{self.backgroundcolor = background; }]; }}- (void) setenabled: (BOOL) theenabled{[SuperSetenabled:theenabled];if(!theenabled) {[self setbackgroundtocolor:[nsnumber numberwithint:uicontrolstatedisabled]]; }Else{[self setbackgroundtocolor:[nsnumber numberwithint:uicontrolstatenormal]]; }}- (void) setselected: (BOOL) theselected{[SuperSetselected:theselected];if(theselected) {[self setbackgroundtocolor:[nsnumber numberwithint:uicontrolstateselected]]; }Else{[self setbackgroundtocolor:[nsnumber numberwithint:uicontrolstatenormal]]; }}- (void) sethighlighted: (BOOL) thehighlighted{[SuperSethighlighted:thehighlighted];if(thehighlighted) {[self setbackgroundtocolor:[nsnumber numberwithint:uicontrolstatehighlighted]]; }Else{[self setbackgroundtocolor:[nsnumber numberwithint:uicontrolstatenormal]]; }}@end
4. Compress the picture in the package with Imagealpha; compressible 20%~50%
Pictures of the IOS App skinny Shenfa