UITextField和UISwitch

定義的寬高:

#define SCREEN_WIDHT [[UIScreen mainScreen] bounds].size.width

#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

#define COMMON_HEIGHT SCREEN_HEIGHT * 0.054

代理:<UITextFieldDelegate>

UITextField這樣用滴:

/** <#description#> */

@property(nonatomic,weak)UITextField * edTF;

UITextField * ed_tf = [[UITextFieldalloc]initWithFrame:CGRectMake(10,64, SCREEN_WIDHT-20,COMMON_HEIGHT)];

    ed_tf.delegate =self;

    ed_tf.placeholder =@"輸入點什麼";

    ed_tf.borderStyle =UITextBorderStyleRoundedRect;

    ed_tf.keyboardType =UIKeyboardTypeNumbersAndPunctuation;

    //清除輸入的內容的叉號

    ed_tf.clearButtonMode =UITextFieldViewModeWhileEditing;

    [self.viewaddSubview:ed_tf];

    _edTF = ed_tf;

通過 _edTF.text獲得輸入的內容。
---------------------------------------------------------------------

UISwitch是這樣用滴:

UISwitch *uiswitch = [[UISwitchalloc]initWithFrame:CGRectMake(10,CGRectGetMaxY(ed_tf.frame)+10 ,SCREEN_WIDHT-20,COMMON_HEIGHT)];

    uiswitch.on =NO;

    [uiswitch addTarget:selfaction:@selector(switchui:)forControlEvents:UIControlEventValueChanged];

    [self.viewaddSubview:uiswitch];

點擊的實現:

-(void)switchui:(id)sender{

    UISwitch *Switchi = (UISwitch *)sender;

    BOOL switchon = Switchi.isOn;

    if(switchon){

        //控制輸入框內容密文顯示

        _edTF.secureTextEntry=YES;

    }else{

        //控制輸入框內容明文顯示

        _edTF.secureTextEntry=NO; 

    }

}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章