码迷,mamicode.com
首页 > 移动开发 > 详细

(iOS)开发中收集的小方法

时间:2014-08-08 21:01:26      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   strong   for   ar   cti   

  • 1.颜色转变成图片

- (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评分跳转

-(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.获取当前系统语言环境

  NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];

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

  NSString* preferredLang = [languages objectAtIndex:0];

  • 4.计算字符串的高度

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.强行关闭app的方法 

私有API
[[UIApplication sharedApplication] performSelector:@selector(terminateWithSuccess)];
C语言方法
exit(0);

(iOS)开发中收集的小方法,布布扣,bubuko.com

(iOS)开发中收集的小方法

标签:style   color   os   io   strong   for   ar   cti   

原文地址:http://www.cnblogs.com/hikoming/p/3899969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!