(iOS)开发中收集的小方法_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > (iOS)开发中收集的小方法

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

 2014/8/8 19:13:14  hikoming  程序员俱乐部  我要评论(0)
  • 摘要:1.颜色转变成图片-(UIImage*)createImageWithColor:(UIColor*)color{CGRectrect=CGRectMake(0.0f,0.0f,1.0f,1.0f);UIGraphicsBeginImageContext(rect.size);CGContextRefcontext=UIGraphicsGetCurrentContext();CGContextSetFillColorWithColor(context,[colorCGColor])
  • 标签:方法 iOS 开发
  • 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);

上一篇: C#几个经常用到的字符串的截取 下一篇: 没有下一篇了!
发表评论
用户名: 匿名