IOS_TextField,UIButton

来源:互联网 发布:软件原型设计 编辑:程序博客网 时间:2024/06/09 19:06

一 :

TextField:

//单行文本输入框

   UITextField *username = [[UITextFieldalloc] initWithFrame:CGRectMake(10,50, 210, 30)];

    username.backgroundColor = [UIColorwhiteColor];

    [self.windowaddSubview:username];

    username.borderStyle =UITextBorderStyleRoundedRect;

    username.placeholder =@"请输入用户名";

    username.textAlignmentNSTextAlignmentCenter;

    [usernamerelease];

    //多行输入

    UITextField *username1 = [[UITextFieldalloc] initWithFrame:CGRectMake(10,140, 210, 60)];

    username1.backgroundColor = [UIColorredColor];

    [self.windowaddSubview:username1];

//    username1.clearButtonMode = UITextBorderStyleRoundedRect;

    //加密输入

//    username.secureTextEntry = YES;

     username1.keyboardType =UIKeyboardTypeURL;


二 : 

Button:

 //UIButton

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

    //title

    button.frame =CGRectMake(80,370, 100, 30);

    button.backgroundColor = [UIColoryellowColor];

    [self.windowaddSubview:button];

    //给button添加标题

    [button setTitle:@"title"forState:UIControlStateNormal];

    //点击的时候有高亮状态

    button.showsTouchWhenHighlighted =YES;

    // 给button指定一个功能方法

    //参数1 :点击按钮之后,让什么对象调用方法(self指当前类的对象)

    //参数2 :让参数1的对象调用方法(写方法名:)

    //参数3 :

    [button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];

    //    [button setTitle:@"注册" forState:UIControlStateNormal];

    //    [button addTarget:self action:@selector(bu) forControlEvents:UIControlEventTouchUpInside];


 //按钮点击方法的写法格式

     //- (void)方法名 :(UIButton *)btn

     -(void) buttonAction:(UIButton *)btn

     {

        NSLog(@"点击");

        self.window.backgroundColor = [UIColorblackColor];

     }










0 0
原创粉丝点击