我的 IOS 筆記——純屬記錄

//1、創建常量字符串。

NSString *astring = @"This is a String!";

//2、創建空字符串,給予賦值。

NSString *astring = [[NSString alloc] init]; 
astring = @"This is a String!";
[astring release];
NSLog(@"astring:%@",astring);
//
NSString *astring = [[NSString alloc] init];
NSLog(@"0x%.8x", astring);
astring=@"This is a String!";
NSLog(@"0x%.8x", astring);
[astring release];
NSLog(@"astring:%@",astring);

//3、在以上方法中,提升速度:initWithString方法

NSString *astring = [[NSString alloc] initWithString:@"This is a String!"];

NSLog(@"astring:%@",astring);

[astring release];

//4、用標準c創建字符串:initWithCString方法
複製代碼

char *Cstring = "This is a String!";

NSString *astring = [[NSString alloc] initWithCString:Cstring];

NSLog(@"astring:%@",astring);

[astring release];

//19、-appendString: and -appendFormat: //把一個字符串接在另一個字符串的末尾
複製代碼

NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];

[String1 appendString:@", I will be adding some character"];
[String1 appendFormat:[NSString stringWithFormat:@", I will be adding some character"]];

NSLog(@"String1:%@",String1);

UILabel自適應寬度

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];//這個frame是初設的,沒關係,後面還會重新設置其size。
[label setNumberOfLines:0];
NSString *s = @"abcdefghijklmn";
UIFont *font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(320,2000);
CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakModeWordWrap];
[label setFrame:CGRectMake(0,0, labelsize.width, labelsize.height)];
[self.view addSubView:label];

Xcode 8.2.1 避開Main.storyboard

1、TARGETS - General 刪除Main
這裏寫圖片描述

2、AppDelegate self.window的設置

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor yellowColor];
    //添加到顯示窗口中
    [self.window setRootViewController:bar];
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];

OC中關於“宏”的一些基本東西

1、程序第一步是在預編譯之前會有一些操作, 例如刪除反斜線和換行符的組合, 將每個註釋用一個空格替代…。

2、然後在進入預編譯的時候, 會尋找可能存在的預處理指定(由#開頭), 例如C中常用的#include, 或者oc中的#import, #define…很多(條件編譯語句…)

3、處理#define的時候,然後預處理器會從#開始, 一直到執行到第一個換行符(寫代碼的時候換行的作用), 自然, #define只會允許定義一行的宏, 不過正因爲上面提到的預處理之前會刪除反斜線和換行符的組合, 所以可以利用反斜線定義多行宏, 在刪除反斜線和換行符的組合後, 邏輯上就成了一行的宏了

4、宏作用在預編譯時期, 其真正的效果就是代碼替換, 而且是直接替換(內聯函數!!!), 這個和函數有着很大的區別, 並且正因爲是直接替換, 在使用的時候就會有一些的注意點了, 這個在後面會給出例子

5、宏可以被稱爲 類對象宏, 類函數宏

6、定義宏的語法很簡單, 一個宏定義由三部分組成 , 三分部之間用空格分開, #define, 宏的名字, 主體 例如第一個宏#define PI(宏的名字) 3.14(主體), 這裏有個注意點就是, 宏的命名和普通的變量命名規則相同

7、宏在預處理階段只進行文本的替換(相當於把代碼拷貝粘貼), 不會進行具體的計算(發生在編譯時期)

************************iOS 創建podfile文件以及使用************************
要先安裝好Cocoapods.

1.打開終端,找到你工程所在路徑 (cd 把你的工程文件夾直接拖過來就可以啦)

2.創建Podfile(輸入 vim Podfile回車)

3.保存文件(:wq)

4.保存好之後會看到工程文件夾下出現 podfile文件,雙擊點開寫上自己需要的第三方的名字,保存後在終端輸入(pod install)

5.等待pod下載好之後,點擊新生成的wesocketDemo.xcworkspace打開工程.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章