Modify the Navigationbar color of a root line

Source: Internet
Author: User

[Self.navigationController.navigationBar setshadowimage:[static colortoimage:[static Colorwithhexstring:[uicolor Red]];

A few static methods in static

+ (UIImage *) Colortoimage: (Uicolor *) color{        cgrect rect=cgrectmake (0.0f0.0f1.0f  1.0f);    Uigraphicsbeginimagecontext (rect.size);     = Uigraphicsgetcurrentcontext ();    Cgcontextsetfillcolorwithcolor (context, [color Cgcolor]);    Cgcontextfillrect (context, rect);         *theimage = uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext ();     return theimage;}

+ (Uicolor *) colorwithhexstring: (NSString *) color{NSString*cstring =[[Color Stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]] uppercaseString]; if([cString Length] <6) {        return[Uicolor Clearcolor]; }        if([cString Hasprefix:@"0X"]) cString= [CString Substringfromindex:2]; if([cString Hasprefix:@"#"]) cString= [CString Substringfromindex:1]; if([cString length]! =6)        return[Uicolor Clearcolor]; //SplitNsrange Range; Range.location=0; Range.length=2; //RNSString*rstring =[cString Substringwithrange:range]; //Grange.location=2; NSString*gstring =[cString Substringwithrange:range]; //Brange.location=4; NSString*bstring =[cString Substringwithrange:range]; //ScanunsignedintR, G, B; [[Nsscanner scannerwithstring:rstring] Scanhexint:&R]; [[Nsscanner scannerwithstring:gstring] Scanhexint:&G]; [[Nsscanner scannerwithstring:bstring] Scanhexint:&b]; return[Uicolor colorwithred: ((float) R/255.0f) Green: ((float) G/255.0f) Blue: ((float) b/255.0f) Alpha:1.0f];}

Modify the Navigationbar color of a root line

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: 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.