首页 > 代码库 > Xcode--代码创建按钮,文本输入框

Xcode--代码创建按钮,文本输入框

//创建按钮    UIButton *btn = [[UIButton alloc] init];    btn.frame = CGRectMake(0, 0, 100, 100);    //    设置按钮在普通状态下的属性//      设置背景图片    UIImage *normal = [UIImage imageNamed:@"btn_01.png"];    [btn setBackgroundImage:normal forState:UIControlStateNormal];        [btn setTitle:@"点我啊" forState:UIControlStateNormal];    [btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];    //    设置按钮在高亮状态下的属性    UIImage *high = [UIImage imageNamed:@"btn_02.png"];    [btn setBackgroundImage:high forState:UIControlStateHighlighted];        [btn setTitle:@"点我啊" forState:UIControlStateHighlighted];    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];//      监听按钮点击    [btn addTarget:self action:@selector(btnclick:)     forControlEvents:UIControlEventTouchUpInside];- (void)btnclick:(UIButton *)btn{        NSLog(@“———%”p,btn);}//创建文本输入框    UITextField *field = [[UITextField alloc] init];    field.frame = CGRectMake(100,100,100,50);    field.backgroundColor = [UIColor redColor];//中点的X    CGFloat centerX = self.view.frame.size.width * 0.5;    CGFloat centerY = self.view.frame.size.height * 0.5’    field.center = CGPointMake(centerX, centerY);//设置字体    field.font = [UIFont systemFontOfSize:30];    [self.view addSubview:field];

 

Xcode--代码创建按钮,文本输入框