UIButton常见用法

//UIButton是iOS中用来响应用户点击的控件,既可以显示文字,也可以显示图片,也可以处理用户交互

    //UIButton的创建,一般采用类方法来创建,不需要释放

    //UIButton 也是UIControl的子类

    

    //1、创建UIButton(一般用类方法)

    //2、配置UIButton

    //3、添加到父视图上面

    

    //创建UIButton

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeSystem];

    //配置UIButton

//    myButton.frame = [CGRectMake(100 , 200 , 50 , 50)];

    [myButton setFrame:CGRectMake(100 , 200 , 80 , 60)];

    //给UIButton设置要显示的文字

    [myButton setTitle:@"login" forState:UIControlStateNormal];

    //设置文字大小

    myButton.titleLabel.font = [UIFont systemFontOfSize:20];

    //给UIButton背景色

//    myButton.backgroundColor = [UIColor orangeColor];

    

    //给UIButton添加点击事件

    [myButton addTarget:self action:@selector(myButtonAction) forControlEvents:UIControlEventTouchUpInside];

    

    //给button添加图片

    [myButton setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];

    [myButton setBackgroundImage:[UIImage imageNamed:@"2.jpg"] forState:UIControlStateHighlighted];

    //给button添加图片,居中,而不是用al

    myButton.contentMode = UIViewContentModeCenter;

    

 

    //添加到父视图上面

    [contentView addSubview:myButton];

转载于:https://www.cnblogs.com/fengkuangIT/p/4520439.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值