一.IBAction 和 IBOutlet
- IBAction:
- 本質(zhì)就是void
- 能讓方法具備連線功能
- IBOutlet
- 能讓屬性具備連線功能
二.Storyboard連線出現(xiàn)的問題
-
連接的屬性代碼被刪除,但連線沒有去掉.會(huì)報(bào)以下錯(cuò)誤:
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
-
連接的方法代碼被刪掉,但是連線沒有去掉.可能會(huì)出現(xiàn)方法找不到錯(cuò)誤
- unrecognized selector sent to instance
三.項(xiàng)目屬性
- Product Name
- 軟件名稱、產(chǎn)品名稱、項(xiàng)目名稱
- Organization Name
- 公司名稱、組織名稱
- Organization Identifier
- 公司的唯一標(biāo)識(shí)
- 一般是公司域名的反寫,比如com.xxxx
- Bundle Identifier
- 軟件的唯一標(biāo)識(shí)
- 一般是Organization Identifier + Product Name
四.UIView常用屬性
@property(nonatomic,readonly) UIView *superView; // 獲得自己父控件對(duì)象
@property(nonatomic,readonly,copy) NSArray *subViews; // 獲得自己所有的子控制對(duì)象
@property(nonatomic) NSInteger tag; // 控件ID標(biāo)識(shí)符,可以通過對(duì)應(yīng)的tag來找對(duì)應(yīng)的控件
@property(nonatomic) CGAffineTransform transform; // 通過該屬性來設(shè)置控件旋轉(zhuǎn)角度,縮放,平移屬性
@property(nonatomic) CGRect frame; // 以父控件的左上角為坐標(biāo)原點(diǎn)
@property(nonatomic) CGRect bounds; // 以自己左上角為坐標(biāo)原點(diǎn),所以bounds的x.y一般為0
@property(nonatomic) CGPoint point; // 以父控件的左上角為坐標(biāo)原點(diǎn)(控件中心的位置)
- (void)addSubView:(UIView *)view; // 添加1個(gè)子控件
- (void)removeFromSuperView; // 從父控件中移除
- (UIView *)viewWithTag:(NSInteger) tag; // 根據(jù)1個(gè)tag找出對(duì)應(yīng)的控件
- (CGSize)sizeThatFits:(CGSize)size; // 默認(rèn)是返回現(xiàn)有的視圖大小
- (void)bringSubviewToFront:(UIView *)view; // 將控件顯示在最上面
- (void)sendSubviewToBack:(UIView *)view; // 將控件顯示在最后面
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; // 將控件插入到對(duì)應(yīng)的index位置
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; // 將控件view顯示到子控件belowSubview的下面
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; // 將控件view顯示到子控件aboveSubview的上面
五.UIButton的常見設(shè)置
- (void)setTitle:(NSString *)title forState:(UIControlState)state; // 設(shè)置按鈕文字
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state ; // 設(shè)置按鈕文字顏色
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state; // 設(shè)置按鈕的小圖片
- (void)setBackgroundImage:(nullable UIImage *)image forState:(UIControlState)state; // 設(shè)置按鈕背影圖片
- (nullable NSString *)titleForState:(UIControlState)state; // 獲取按鈕文字
- (nullable UIColor *)titleColorForState:(UIControlState)state; // 獲取按鈕文字顏色
- (nullable UIImage *)imageForState:(UIControlState)state; // 獲取按鈕小圖片
- (nullable UIImage *)backgroundImageForState:(UIControlState)state; // 獲取按鈕背景圖片
六.UILabel的常見設(shè)置
@property(nonatomic,copy) NSString *text; // 顯示文字
@property(nonatomic,retain) UIFont *font; // 顯示字體
@property(nonatomic,retain) UIColor *color; // 顯示文字顏色
@property(nonatomic) NSTextAlignment textAlignment; // 對(duì)齊模式(左/中/右)
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize; // 系統(tǒng)默認(rèn)字體
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; // 粗體
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; // 斜體
七.定時(shí)任務(wù)
- 方法1:performSelector
// 1s后自動(dòng)調(diào)用self的test方法
[self performSelector:@selector(test) withObject:nil afterDelay:1.5];
- 方法2:GCD
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 1s后自動(dòng)執(zhí)行這個(gè)block里面的代碼
self.hud.alpha = 0.0;
});
- 方法3:NSTimer
// 1s后自動(dòng)調(diào)用self的hideHUD方法
[NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(test) userInfo:nil repeats:NO];
// repeats如果為YES,意味著每隔1s都會(huì)調(diào)用一次self的hidHUD方法
八.常見問題
1. 控件看不見
- 寬度或者高度其實(shí)為0
- 位置不對(duì)(比如是個(gè)負(fù)數(shù)或者超大的數(shù),已經(jīng)超出屏幕)
- hidden == YES
- alpha <= 0.01
- 沒有設(shè)置背景色、沒有設(shè)置內(nèi)容
- 可能是文字顏色和背景色一樣
2. 項(xiàng)目中某個(gè).m文件無法使用
- 檢查:Build Phases -> Compile Sources
- 項(xiàng)目里面的某個(gè)資源文件(比如plist、音頻等)無法使用
- 檢查:Build Phases -> Copy Bundle Resources