標籤:
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 犄角旮旯的知識