码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-12-05 10:45:24      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   on   div   

//创建按钮
    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--代码创建按钮,文本输入框

标签:style   blog   io   ar   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/ZhangYuGe/p/4145903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!