Small methods collected in development (IOS)

Source: Internet
Author: User

    • 1. Turn color into pictures

-(UIImage *) Createimagewithcolor: (Uicolor *) color
{
CGRect rect = CGRectMake (0.0f, 0.0f, 1.0f, 1.0f);
Uigraphicsbeginimagecontext (rect.size);
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Cgcontextsetfillcolorwithcolor (context, [color Cgcolor]);
Cgcontextfillrect (context, rect);
UIImage *theimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return theimage;
}

    • 2.app Scoring Jump

-(void) Gotoappstore
{
NSString *str = [NSString stringWithFormat:
@ "itms-apps://ax.itunes.apple.com/webobjects/mzstore.woa/wa/viewcontentsuserreviews?type=purple+software& Id=%d ", 547203890];
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];
}

    • 3. Get the current system language environment

nsuserdefaults* defs = [Nsuserdefaults standarduserdefaults];

nsarray* languages = [defs objectforkey:@ "Applelanguages"];

  nsstring* Preferredlang = [languages objectatindex:0];

    • 4. Calculating the height of a string

Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc]init];

Paragraphstyle.linebreakmode = nslinebreakbywordwrapping;

Nsdictionary *dicatt = [Nsdictionary dictionarywithobjectsandkeys:[uifont systemfontofsize:15],nsfontattributename, Paragraphstyle.copy,nsparagraphstyleattributename, nil];

nsattributedstring *attribute = [[nsattributedstring alloc]initwithstring:str Attributes:dicatt];

CGRect frame = [attribute Boundingrectwithsize:cgsizemake (maxfloat) options: Nsstringdrawinguseslinefragmentorigin Context:nil];

    • 5. How to forcibly close the app 

Private API
[[UIApplication sharedapplication] Performselector: @selector (terminatewithsuccess)];
C Language Method
Exit (0);

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.