• (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);

  • 相关阅读:
    SQL SELECT INTO 语句
    跨站脚本攻击测试[转]
    Visual Studio 2008中如何比较二个数据库的架构【Schema】和数据【Data】并同步 [转贴]
    联表UPDATE
    网站架构策划方案
    概念模型 逻辑模型 物理模型 区别
    Repeater嵌套绑定Repeater
    .net 2.0升级到了.net 3.5,开发工具从vs2005转为vs2008
    你必须知道的C#的25个基础概念(附演示) 【转】
    window2003中,在IIS中,如何解决不能播放.FLV文件
  • 原文地址:https://www.cnblogs.com/hikoming/p/3899969.html
Copyright © 2020-2023  润新知