UIBUTTON电话界面

   //7.0着色

    //父视图着色改变 那么上面的所有的子视图着色都会改变

    self.window.tintColor = [UIColor redColor];

    

    //7.0无边框按钮

    for (int i=0; i<7 ;i++) {

        UIButton *b =[UIButton buttonWithType:i];

        b.frame = CGRectMake(50, i*50+20, 100, 50) ;

        if (i == 4) {

            //dark button

            b.tintColor =[UIColor grayColor];

        }

        

        [self.window addSubview:b];

    }

    //自定义按钮

//    UIButton *b1 = [UIButton buttonWithType:UIButtonTypeCustom];

//    b1.frame = CGRectMake(200, 200, 50, 50);

//    b1.layer.cornerRadius =25.0;

//    b1.layer.borderWidth = 2.0;

//    b1.layer.borderColor =[UIColor grayColor].CGColor;

//    [b1 setTitle:@"9" forState:UIControlStateNormal];

//    [b1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

//    

//    [self.window addSubview:b1];

    

    UIImageView * imgView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

    //iOSpng格式的图片支持较好

    imgView.image =[UIImage imageNamed:@"640*1136"];

    [self.window addSubview:imgView];

    [imgView release];

    //10个按钮放在UIImageView

    int k = 1;

    for (int i = 0; i<3; i++) {

        for (int j = 0; j<3; j++) {

            UIColor *color = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];

            UIButton *b1 = [UIButton buttonWithType:UIButtonTypeCustom];


            b1.frame = CGRectMake(20 +100*j, 90+100*i, 80, 80);

            b1.layer.cornerRadius =40;

            b1.layer.borderColor= [UIColor grayColor].CGColor;

            b1.layer.borderWidth =3.0;

            NSString *str = [NSString stringWithFormat:@"%d",k++];

            [b1 setTitle:str forState:UIControlStateNormal];

            //事件传参

            [b1 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

            [b1 setTitleColor:color forState:UIControlStateNormal];

            b1.titleLabel.font = [UIFont systemFontOfSize:40];

            [imgView addSubview:b1];

            

            //UIImageView默认是不能接受点击事件的

            imgView.userInteractionEnabled = YES;

        }

    }

    UIButton *b1 = [UIButton buttonWithType:UIButtonTypeCustom];

    _num = [[NSMutableString alloc] init];

    

    b1.frame = CGRectMake(120, 390, 80, 80);

    b1.layer.cornerRadius =40;

    b1.layer.borderColor= [UIColor grayColor].CGColor;

    b1.layer.borderWidth =3.0;

    [b1 setTitle:@"0" forState:UIControlStateNormal];

    //添加事件

    [b1 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

    //移除事件

    [b1 removeTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

    [b1 setTitleColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0] forState:UIControlStateNormal];

    b1.titleLabel.font = [UIFont systemFontOfSize:40];

    [imgView addSubview:b1];

    

    label = [[[UILabel alloc] initWithFrame:CGRectMake(20, 30, 280, 50)] retain];

    label.backgroundColor = [UIColor grayColor];

    label.textAlignment = NSTextAlignmentCenter;

    label.font =[UIFont systemFontOfSize:40];

    [self.window addSubview:label];

    

    return YES;

}

//用户点击了哪个按钮,就把哪个按钮作为参数传递过来 sender

/*监听用户的点击事件 每次点击 代码从该方法开始执行

  用户每一次点击都是一个事件循环 RunLoop

  每一个时间循环都会自动加上自动释放池

  事件循环结束后 系统会回收自动释放池中的对象

 */

- (void)click:(id)sender

{

    NSLog(@"sender is %@",sender);

    //获取按钮的标题

//    NSLog(@"%@",[sender titleForState:UIControlStateNormal]);

//    [_num appendString:[sender titleForState:UIControlStateNormal]];

//    label.text =_num;

//    label.font = [UIFont systemFontOfSize:40];

//    label.textAlignment = NSTextAlignmentCenter;  或者

    if (label.text.length ==0) {

        label.text =[sender titleForState:UIControlStateNormal];

    }else{

        if (label.text.length>10) {

            NSLog(@"这是火星的号码吗?");

        }

        NSString *str = label.text;

        //该方法中str不能为nil

        NSString *newStr = [str stringByAppendingString:[sender titleForState:UIControlStateNormal]];

        label.text = newStr;

    }

    

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值