iOS development-collection of infrequently used but useful small methods and tricks

Source: Internet
Author: User

Original link: http://blog.5ibc.net/p/90386.html

1. Color transforms 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, the method of forcibly closing the app

Private Api[[uiapplication sharedapplication] Performselector: @selector (terminatewithsuccess)];//C language method exit (0);

3, when using the View zoom, layer.border.width with the view magnification, there will be a jagged problem, to solve this problem need to set this familiar.

self.layer.allowsEdgeAntialiasing = YES;

4, button on Tableviewcell, click Get Location row

UITableViewCell *cell = (UITableViewCell *) [[btn Superview] superview]; Nsindexpath * Indexpath = [Self.tableview Indexpathforcell:cell];

5, iphone in order to save power so there is an automatic sleep mechanism, if you want to let our app does not automatically go to sleep only need to set uiapplication idletimerdisabled property is YES. (Never misuse)

6, Uiapplicationuserdidtakescreenshotnotification notification, when the user screenshots triggered

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (screencapture) Name: Uiapplicationuserdidtakescreenshotnotification object:nil];-(void) screencapture{    //dosomething}

iOS development-collection of infrequently used but useful small methods and tricks

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.