學習IOS開發UI篇--UI知識點總結(一) UIButton/UITextField

來源:互聯網
上載者:User

標籤:c   style   a   ext   color   int   

  UIkit架構下的幾個基本控制項,UIButton,UITextField,UILabel,UIImageView,UIScrollView,UITableView,UITableViewCell,UIPageControl;

  他們的繼承關係,UILabel,UIImageView,UIScrollView,UITableViewCell,直接繼承自UIView;

         UIButton,UITextField,UIPageControl,繼承自UIControl;

         UIControl繼承自UIView;

  補充:在按鈕中添加背景圖片時候設計展開的方法

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); // the interior is resized according to the resizingMode

*** 需要設定按鈕的contentEdgeInsets 屬性 

@property(nonatomic)          UIEdgeInsets contentEdgeInsets ; // default is UIEdgeInsetsZero

  UIButton:UIButton很常用,屬性雖然簡單,不過初學者常會弄不清楚;

  在設定屬性的時候需要注意,UIButton中預設有

@property(nonatomic,readonly,retain) UILabel     *titleLabel NS_AVAILABLE_IOS(3_0); (在UIButton不能建立titleLable屬性)

@property(nonatomic,readonly,retain) UIImageView *imageView  NS_AVAILABLE_IOS(3_0);

@property(nonatomic,readonly,retain) NSString *currentTitle;             // normal/highlighted/selected/disabled. can return nil

@property(nonatomic,readonly,retain) UIColor  *currentTitleColor;        // normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1) 

  在調用方法的時候容易直接用點文法,導致顯示錯誤,正確調用方法應該是

- (void)setTitle:(NSString *)title forState:(UIControlState)state;                // default is nil. title is assumed to be single line

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state

- (void)setImage:(UIImage *)image forState:(UIControlState)state;          // default is nil. should be same size if different for different states

 

  UITextFiled: 常用屬性

@property(nonatomic,copy)   NSString               *text;                 // default is nil

@property(nonatomic,copy)   NSAttributedString     *attributedText NS_AVAILABLE_IOS(6_0); // default is nil

@property(nonatomic,retain) UIColor                *textColor;            // default is nil. use opaque black

@property(nonatomic,retain) UIFont                 *font;                 // default is nil. use system font 12 pt

@property(nonatomic)        NSTextAlignment         textAlignment;        // default is NSLeftTextAlignment

@property(nonatomic,retain) UIView              *leftView;        // e.g. magnifying glass (可以在左側預留輸入空白)

@property(nonatomic)        UITextFieldViewMode  leftViewMode;    // sets when the left view shows up. default is UITextFieldViewModeNever

  代理方法:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.

- (void)textFieldDidBeginEditing:(UITextField *)textField;           // became first responder

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;          // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end

- (void)textFieldDidEndEditing:(UITextField *)textField;             // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called 

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // return NO to not change text 

- (BOOL)textFieldShouldClear:(UITextField *)textField;               // called when clear button pressed. return NO to ignore (no notifications)

- (BOOL)textFieldShouldReturn:(UITextField *)textField;              // called when ‘return‘ key pressed. return NO to ignore.(在次方法中設定關閉鍵盤)

 


    

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.