您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 使用技巧 >> iOS 7 技巧

iOS 開發:Xcode 常用程式碼快速上手小抄

編輯:iOS 7 技巧

下面為各位朋友整理一份 iOS 開發中 Xcode 的常用範例小抄,都是實作時經常會用到的片段,希望能幫助到大家。


知識庫

載入一張圖片

UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

imageView.image=[UIImage imageNamed:@"22.png"];
[self.view addSubview:imageView];

彈出提示視窗

NSString *msg = @"f*au*ck U";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"message" message:msg delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; [alert show];

整合一個彈窗方法

NSString *a = [NSString stringWithFormat:@"group s %d",index];
[self alert:a];

字串與數字轉換

1,字串拼接

NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];
2,字串轉 int

int intString = [newString intValue];

3,int 轉字串

NSString *stringInt = [NSString stringWithFormat:@"%d",intString];

解決中文亂碼問題(POST 與 textField 皆適用):
[NSString stringWithCString:[str UTF8String] encoding:NSUTF8StringEncoding];

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved