(IOS) Small collection methods in development, ios development collection methods

Source: Internet
Author: User

(IOS) Small collection methods in development, ios development collection methods

  • 1. color to image

-(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. Jump to app scoring

-(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. Obtain the current system language environment

NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];

NSArray * ages = [defs objectForKey: @ "AppleLanguages"];

  NSString * preferredLang = [ages objectAtIndex: 0];

  • 4. Calculate the string height

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 (200, MAXFLOAT) options: NSStringDrawingUsesLineFragmentOrigin context: nil];

  • 5. Forcibly disable the app 

Private API
[[UIApplication sharedApplication] performSelector: @ selector (terminateWithSuccess)];
C Language Method
Exit (0 );


Ios development process and Learning Method

If programming has no foundation, consider training.

If you have to do it yourself, go to the bookstore and look for books. You can purchase them if you can understand them.

In ios development, you may encounter many methods defined in system protocols that you do not understand.

This is the proxy method of the scrolling control that comes with ios. You can click command to view this method, or Baidu will know how to use UIPickerView.

Related Article

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.