Pictures of the IOS App skinny Shenfa

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.