//创建按钮
    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];

 

posted on 2014-12-05 09:38  墓厄  阅读(247)  评论(0编辑  收藏  举报