iOS 犄角旮旯的知識

來源:互聯網
上載者:User

標籤:

1、全域變數

static NSInteger kImageHeight = 300;

#define kImageHeight 300

2、通知中樞

開始編輯

UITextViewTextDidBeginEditingNotification 

正在更改

UITextViewTextDidChangeNotification

結束編譯

UITextViewTextDidEndEditingNotification

 

//註冊文字改變通知

 

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChangeNotifition:) name:UITextViewTextDidChangeNotification object:nil];

- (void)dealloc

{

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:nil];

 

}

 

3、動態載入(不用匯入標頭檔)

 

NSArray * vcNames1 = @[@"FriendViewController"];

NSArray * vcNames2 = @[@"SwipeViewController",@"SharkViewController"];

 

self.viewControllers = @[vcNames1,vcNames2];

NSString * vcName = self.viewControllers[indexPath.section][indexPath.row];

 

UIViewController * vc = [[NSClassFromString(vcName) alloc] init];

例如:自訂Button類:UIButton

在viewController 聲稱對應button對象 進行重寫init方法來定義 類型

不能在button類中寫button屬性 因為在懶載入中 添加點擊事件 調不到

4、更改圖片顏色; 忽略它的顏色資訊

image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

 

5、項目結構

6、 當導航視圖控制器壓棧時,隱藏tabbar

    vc.hidesBottomBarWhenPushed = YES;

7、圖片加邊框,代碼:

imageLayer.borderColor = [UIColor grayColor].CGColor;  //邊框顏色imageLayer.borderWidth = 2.0;  //邊框寬度
8、磊神教學Block

(1)聲明block變數並設定傳回值類型

typedef NSString *(^MYBlock)(NSString *);

@property (nonatomic, copy) MYBlock block;

(2)調用Block方法(發送),並接收傳回值

NSString * string = self.block(@"123”);

NSLog(@“%@“,string);

(3)調用Block方法(接收),並接收傳回值

self.ceshi.block =  ^ (NSString *string) {

 

NSLog(@"%@",string);

 

return@“peng";

};

(4)利用typedef定義block類型(和指向函數的指標很像)

(類)Typedef int(^MyBlock)(int ,int);

以後就可以利用這種類型來定義block變數了。

(類)MyBlock block1,block2;  

(類)int i = block1(3,4);

(主)block1=^(int a,int b){

return a-b;

};

__weak ViewController *mySelf = self; block中避免循環參考

 

iOS 犄角旮旯的知識

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.