標籤:
1. 設定按鈕文字的尺寸 為 按鈕自己的尺寸 button.size = [button.currentTitle sizeWithFont:button.titleLabel.font]; button.backgroundColor=[UIColor redColor];2. 常用尺寸/** 44 : cell的預設高度、導覽列的可見高度 49 : UITabBar的預設高度 64 : 從視窗頂部到導覽列底部 20 : 狀態列高度 320 : 豎屏情況下的螢幕寬度 480 : 豎屏情況下的3.5 inch 的螢幕高度 568 : 豎屏情況下的4.0 inch 的螢幕高度 */3. textview改變通知#warning 不要設定自己的代理為自己本身 // 監聽內部文字改變// self.delegate = self; /** 監聽控制項的事件: 1.delegate 2.- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 3.通知 */ // 當使用者通過鍵盤修改了self的文字,self就會自動發出一個UITextViewTextDidChangeNotification通知 // 一旦發出上面的通知,就會調用self的textDidChange方法 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self];4. copy策略,重寫setter方法,- (void)setPlacehoder:(NSString *)placehoder{#warning 如果是copy策略,setter最好這麼寫 _placehoder = [placehoder copy]; // 設定文字 self.placehoderLabel.text = placehoder; // 重新計運算元控制項的fame, [self setNeedsLayout];//重新布局子控制項}4. UiTabbar bug修複- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UINavigationController *)viewController{ UIViewController *vc = [viewController.viewControllers firstObject]; if ([vc isKindOfClass:[HMHomeViewController class]]) { if (self.lastSelectedViewContoller == vc) { [self.home refresh:YES]; } else { [self.home refresh:NO]; } } self.lastSelectedViewContoller = vc;} self.lastSelectedViewContoller = vc; /** 其實在這裡隱藏著一個問題,如果你的4個TabBar都是指向4個NavigationController,那麼沒有問題,運行OK。 但如果你的4個TabBar有任何一個指向的不是NavigationController,那麼程式就會crash。因為非NavigationController不能夠響應 popToRootViewControllerAnimated: 方法。 */ if ([viewController isKindOfClass:[UINavigationController class]]) { [(UINavigationController *)viewController popToRootViewControllerAnimated:YES]; }
ios基礎筆記(一)