(iOS)開發中收集的小方法,ios開發收集方法

來源:互聯網
上載者:User

(iOS)開發中收集的小方法,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);


ios開發流程及學習方法

編程零基礎的話,考慮培訓吧。

一定要自己搞的話,去書店找找書,看哪本能看得懂就買來學。
 
ios開發中遇到很多不懂的系統協議中定義的方法,可以去什地方查看

這個是ios內建的那種滾動選擇的控制項的代理方法。command 點這個方法就能點進去看,或者百度一下 UIPickerView 的使用就知道怎麼用了
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.