UI基礎控件入門1

簡單了解

  • 程序執(zhí)行的過程?
    1. 系統(tǒng)讀取Main.storyboard;
    2. 創(chuàng)建箭頭所指向的控制器;
    3. 根據(jù)storyboard文件中描述創(chuàng)建UIViewController的UIView對象,以及UIView內(nèi)部的所有子控件;
    4. 將控制器的根view以及內(nèi)部的子控件顯示在屏幕上。
  • UIView和UIViewController?
    1. 屏幕上所有能看的見的東西都是UIView,所有的控件都繼承自UIView,UIView是一個容器,能容納其他的任何控件;
    2. UIViewController用來管理界面上的UIView。每當顯示一個新界面時,首先會創(chuàng)建一個新的UIViewController對象,然后創(chuàng)建一個對應的全屏的UIView,UIViewController負責管理這個全屏的UIView;
    3. UIViewController就是UIView的大管家,負責創(chuàng)建、顯示、銷毀UIView,負責監(jiān)聽UIView的內(nèi)部事件,負責處理UIView與用戶的交互;
    4. UIViewController對象內(nèi)部有一個UIView的屬性。
@property (nonatomic, retain) UIView *view;
  • frame、bounds、center的區(qū)別?
    1. frame表示尺寸和位置,位置以父控件左上角為坐標原點;
    2. bounds表示尺寸和位置,位置以自己左上角為坐標原點,所以一般bounds的x\y一般為0;
    3. center表示控件的中心點坐標,以父控件的左上角為坐標原點。
@property (nonatomic) CGRect frame;
@property (nonatomic) CGRect bounds;
@property (nonatomic) CGPoint center;
  • transform的平移、縮放、旋轉?
    1. transform修改控件位置形狀,本質是修改了坐標系;
    2. 設置某個子控件的tag屬性后,可以通過父控件的viewWithTag:方法找到子控件;
    3. transform的平移、縮放、旋轉都有相對于最初狀態(tài)的改變方式,以及在當前的transform基礎上的改變方式;
    4. transform的縮放,參數(shù)是縮放的倍數(shù);
    5. 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
  • 懶加載(延遲加載)?
    1. 懶加載:只有當使用的時候才去加載數(shù)據(jù),數(shù)據(jù)只會被加載一次,以后再次使用不再重新加載數(shù)據(jù);
    2. 懶加載的使用:重寫某個屬性的getter方法。

常見控件

  • 按鈕UIButton?
    1. UIButton按鈕是由UILabel和UIImageView組成的;
    2. 按鈕可以處理點擊事件,繼承自UIControl;
    3. 按鈕既能顯示圖片又能顯示文字。
+ (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)下按鈕中的背景圖片
  • 文本框UITextFiled?
@property(nonatomic,copy) NSString *text; // 文本框文字
@property(nonatomic,retain) UIColor *textColor; // 文字顏色
@property(nonatomic,retain) UIFont *font; // 字體
@property(nonatomic) NSTextAlignment textAlignment; // 對齊方式
@property(nonatomic,copy) NSString *placeholder; // 占位符
  • 標簽UILabel?
@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?
    1. UIImageView繼承自UIView,默認情況下不能處理點擊事件;
    2. 加載圖片的兩種方式:
      • 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í)行動畫
  • 讓某個控件產(chǎn)生圓角?
nameView.layer.cornerRadius = 5;
nameView.layer.masksToBounds = YES;
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 15,316評論 4 61
  • 被愛與愛人都并不是一件很輕松很容易的事情。前幾日喝醉,應該說是從上海回來后一直都不大清醒,因為心境的原因急于想在別...
    Anngge閱讀 285評論 0 1
  • 修煉多年還是控制不好自己的情緒,有時候反而不及以前。語言冷暴力的殺傷力更強更狠,傷感情,最主要的是根本沒有任何解決...
    Lunar_王閱讀 484評論 0 0
  • 簡書,你就是我的情人。 當從喜馬拉雅聽說了簡書的存在時,我的心就怦怦怦亂跳,用我們醫(yī)學專業(yè)術語來描述,叫心動過速心...
    極簡書生閱讀 284評論 1 1

友情鏈接更多精彩內(nèi)容