ios基礎控制項之UITextField常用方法彙總

2021-09-23 22:46:01 字數 1423 閱讀 5960

文字控制項(uitextfield)繼承了uicontrol控制項,所以作為活動控制項使用!建立該控制項有兩種方法:一、拖控制項。二、純**搞定。其實本質一樣。不過還是建議採用純**,這樣對控制項的可定製性非常高。
textfield=[[uitextfield alloc]initwithframe:cgrectmake(120.0f, 80.0f, 150.0f, 30.0f)];

[textfield setborderstyle:uitextborderstyleroundedrect];//外框型別

textfield.placeholder=@」請輸入:」;//預設顯示的字

textfield.securetextentry=yes;//是否為密碼式的輸入框

textfield.clearbuttonmode=uitextfieldviewmodewhileediting;

textfield.delegate=self;

textfield.keyboardtype=uikeyboardtypedefault;//鍵盤顯示型別

textfield.autocapitalizationtype=uitextautocorrectiontypeyes;//是否開啟自動提醒更正功能

textfield.contentverticalalignment=uicontrolcontentverticalalignmentcenter;//居中顯示

typedef enum uicontrolcontentverticalalignment;

textfield.textcolor=[uicolor redcolor];//字型顏色

textfield.font=[uifont fontwithname:@」times new roman」 size:35];//字型型別以及尺寸

textfield.background=[uiimage imagenamed:@」background.png」];//背景

[self.view addsubview:textfield];
//委託方法

-(void)textfielddidbeginediting:(uitextfield *)textfield

-(void)textfielddidendediting:(uitextfield *)textfield

-(bool)textfieldshouldreturn:(uitextfield *)textfield

//限定文字框的輸入字數

-(bool)textfield:(uitextfield )textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring )string

return yes;}

ios基礎控制項之開關按鈕(UISwitch)

uiswitch控制項是ios開發的基礎控制項,是非常簡單的乙個控制項,因為它的方法比較少。uiswitch繼承於uicontrol基類,因此可以當成活動控制項使用。注意 開關狀態通過它的on屬性進行讀取,該屬性是乙個bool屬性 建立 uiswitch myswitch uiswitch allo...

ios基礎控制項之開關按鈕(UISwitch)

uiswitch控制項是ios開發的基礎控制項,是非常簡單的乙個控制項,因為它的方法比較少。uiswitch繼承於uicontrol基類,因此可以當成活動控制項使用。注意 開關狀態通過它的on屬性進行讀取,該屬性是乙個bool屬性 建立 uiswitch myswitch uiswitch allo...

iOS開發控制項基礎

一 使用plist檔案 使用plist檔案的目的 將資料和 分離。載入方法 nsstring path nsbundle mainbundle pathforresource imagedata oftype plist nsarray imagelist nsarray arraywithcont...