簡單了解
- 程序執(zhí)行的過程?
- 系統(tǒng)讀取Main.storyboard;
- 創(chuàng)建箭頭所指向的控制器;
- 根據(jù)storyboard文件中描述創(chuàng)建UIViewController的UIView對象,以及UIView內(nèi)部的所有子控件;
- 將控制器的根view以及內(nèi)部的子控件顯示在屏幕上。
- UIView和UIViewController?
- 屏幕上所有能看的見的東西都是UIView,所有的控件都繼承自UIView,UIView是一個容器,能容納其他的任何控件;
- UIViewController用來管理界面上的UIView。每當顯示一個新界面時,首先會創(chuàng)建一個新的UIViewController對象,然后創(chuàng)建一個對應的全屏的UIView,UIViewController負責管理這個全屏的UIView;
- UIViewController就是UIView的大管家,負責創(chuàng)建、顯示、銷毀UIView,負責監(jiān)聽UIView的內(nèi)部事件,負責處理UIView與用戶的交互;
- UIViewController對象內(nèi)部有一個UIView的屬性。
@property (nonatomic, retain) UIView *view;
- frame、bounds、center的區(qū)別?
- frame表示尺寸和位置,位置以父控件左上角為坐標原點;
- bounds表示尺寸和位置,位置以自己左上角為坐標原點,所以一般bounds的x\y一般為0;
- center表示控件的中心點坐標,以父控件的左上角為坐標原點。
@property (nonatomic) CGRect frame;
@property (nonatomic) CGRect bounds;
@property (nonatomic) CGPoint center;
- transform的平移、縮放、旋轉?
- transform修改控件位置形狀,本質是修改了坐標系;
- 設置某個子控件的tag屬性后,可以通過父控件的
viewWithTag:方法找到子控件;
- transform的平移、縮放、旋轉都有相對于最初狀態(tài)的改變方式,以及在當前的transform基礎上的改變方式;
- transform的縮放,參數(shù)是縮放的倍數(shù);
- transform的旋轉:
- 旋轉的參數(shù)是弧度;
- 如果數(shù)值是正數(shù)的話,順時針旋轉,如果數(shù)值是負值的話,逆時針旋轉;
- 特例:如果旋轉π,無論正負都是順時針,如果想逆時針旋轉可以設置參數(shù)為-(M_PI -M_PI*0.000001)。
- (UIView *)viewWithTag:(NSInteger)tag; // 根據(jù)tag取得當前控件內(nèi)部的子控件,需要類型強轉
- (void)removeFromSuperview; // 從父控件中移除
- (void)addSubview:(UIView *)view; // 添加一個子控件view
imgBtn.transform = CGAffineTransformMakeTranslation(0, -20); // 相對于最初狀態(tài)的平移
imgBtn.transform = CGAffineTransformTranslate(imgBtn.transform, 0, -20); // 在當前的transform基礎上平移
imgBtn.transform = CGAffineTransformRotate(imgBtn.transform, M_PI_4); // 在當前transform的基礎上順時針旋轉90°
imgBtn.transform = CGAffineTransformScale(imgBtn.transform, 0.5, 0.5); // 在當前transform的基礎上縮放
imgBtn.transform = CGAffineTransformIdentity; // 清空之前設置的transform
- 懶加載(延遲加載)?
- 懶加載:只有當使用的時候才去加載數(shù)據(jù),數(shù)據(jù)只會被加載一次,以后再次使用不再重新加載數(shù)據(jù);
- 懶加載的使用:重寫某個屬性的getter方法。
常見控件
- 按鈕UIButton?
- UIButton按鈕是由UILabel和UIImageView組成的;
- 按鈕可以處理點擊事件,繼承自UIControl;
- 按鈕既能顯示圖片又能顯示文字。
+ (id)buttonWithType:(UIButtonType)buttonType; // 類方法創(chuàng)建一個按鈕對象
@property(nonatomic) UIEdgeInsets contentEdgeInsets; // 設置按鈕內(nèi)容的邊距
@property(nonatomic) UIEdgeInsets titleEdgeInsets; // 設置按鈕中文字的邊距
@property(nonatomic) UIEdgeInsets imageEdgeInsets; // 設置按鈕中圖片的邊距
@property(nonatomic) BOOL adjustsImageWhenHighlighted; // 高亮狀態(tài)下是否調(diào)整圖片
@property(nonatomic) BOOL adjustsImageWhenDisabled; // 禁用狀態(tài)下是否調(diào)整按鈕中的圖片
@property(nonatomic,readonly) UIButtonType buttonType; // 獲取按鈕的樣式
@property(nonatomic,readonly,retain) NSString *currentTitle; // 獲取當前狀態(tài)下按鈕中的文字
@property(nonatomic,readonly,retain) UIColor *currentTitleColor; // 獲取當前狀態(tài)下按鈕中的文字顏色
@property(nonatomic,readonly,retain) UIImage *currentImage; // 獲取當前狀態(tài)下按鈕中的圖片
@property(nonatomic,readonly,retain) UIImage *currentBackgroundImage; // 獲取當前狀態(tài)下按鈕中的背景圖片
@property(nonatomic,readonly,retain) UILabel *titleLabel; // 獲取按鈕中的label屬性
@property(nonatomic,readonly,retain) UIImageView *imageView; // 獲取按鈕中的imageView屬性
- (void)setTitle:(NSString *)title forState:(UIControlState)state; // 設置不同狀態(tài)下按鈕中的文字
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state; // 設置不同狀態(tài)下按鈕中的文字顏色
- (void)setImage:(UIImage *)image forState:(UIControlState)state; // 設置不同狀態(tài)下按鈕中的圖片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state; // 設置不同狀態(tài)下按鈕中的背景圖片
@property(nonatomic,copy) NSString *text; // 文本框文字
@property(nonatomic,retain) UIColor *textColor; // 文字顏色
@property(nonatomic,retain) UIFont *font; // 字體
@property(nonatomic) NSTextAlignment textAlignment; // 對齊方式
@property(nonatomic,copy) NSString *placeholder; // 占位符
@property(nonatomic,copy) NSString *text; // 標簽文字
@property(nonatomic,retain) UIFont *font; // 文字字體
@property(nonatomic,retain) UIColor *textColor; // 文字顏色
@property(nonatomic) NSTextAlignment textAlignment; // 文字對齊方式
@property(nonatomic) NSInteger numberOfLines; // 設置為0時自動換行
- 圖片UIImageView?
- UIImageView繼承自UIView,默認情況下不能處理點擊事件;
- 加載圖片的兩種方式:
-
imageNamed:當圖片使用完成后會把圖片緩存在內(nèi)存中不釋放;
- 只占用一組圖片的內(nèi)存,
imageWithContentsOfFile:此方法使用時,圖片不能放在Imags.xcassets中。
@property(nonatomic,retain) UIImage *image; // 設置圖片
@property(nonatomic,copy) NSArray *animationImages; // 設置UIImageView的幀動畫
@property(nonatomic) NSTimeInterval animationDuration; // 動畫持續(xù)時間
@property(nonatomic) NSInteger animationRepeatCount; // 動畫重復次數(shù)
- (void)startAnimating; // 開始動畫
- (void)stopAnimating; // 結束動畫
- (BOOL)isAnimating; // 是否正在執(zhí)行動畫
nameView.layer.cornerRadius = 5;
nameView.layer.masksToBounds = YES;