zoukankan      html  css  js  c++  java
  • UIButton常用属性小结(编辑中。。。)

      Button的功能很黄很暴力,即能显示文字,又能显示图片,还能随时调整内部图片和文字的位置,用的地方很多。

    (1)按钮常用的四种状态:

      normal(普通状态)

      默认情况(Default)

      对应的枚举常量:UIControlStateNormal

      highlighted(高亮状态)

      按钮被按下去的时候(手指还未松开)

      对应的枚举常量:UIControlStateHighlighted

      selected (选中状态)

      选没选中由我们自行设定

      对应的枚举常量:UIControlStateSelected

      disabled(失效状态,不可用状态)

      如果enabled属性为NO,就是处于disable状态,代表按钮不可以被点击

      对应的枚举常量:UIControlStateDisabled

    (2)创建button:+ (id)buttonWithType:(UIButtonType)buttonType;

    typedef NS_ENUM(NSInteger, UIButtonType) {

        UIButtonTypeCustom = 0,            // no button type

        UIButtonTypeSystem,                // standard system button

        UIButtonTypeDetailDisclosure,

        UIButtonTypeInfoLight,

        UIButtonTypeInfoDark,

        UIButtonTypeContactAdd, 

        UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead

    };

      常用的是UIButtonTypeCustom和UIButtonTypeSystem,一般选用UIButtonTypeSystem,当你需要对button进行一些个性化的设置时,比如button的选中状态与未选中状态,字体,图片这些不同时,就必须要选择UIButtonTypeCustom,不然,选中状态时,按钮的上面会出现一个蓝色的竖条条。

    (2)按钮的常用属性

      Button.titleLabel.font = [UIFont systemFontOfSize:20];   //改变button字体大小

    (3)button的描边

    (4)button的四角设置弧度

    (5)

    (6)

    (7)

    (8)

    (9)

    (10)

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

        

        button.frame = CGRectMake(100, 100, 200, 100);

        

        //[button setTitle:@"呵呵..." forState:UIControlStateNormal];

        

        //button.backgroundColor = [UIColor lightGrayColor];

        

        //[button setTintColor:[UIColor yellowColor]];

        

        

        

        button.titleLabel.text = @"hehe";

        

        

        button.showsTouchWhenHighlighted=YES;

        

        [button addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];

        

        //将标签加入视图

        [self.view addSubview:button];

    }

    -(void)addButton:(UIButton*)button{

        button.selected = !button.selected;

        if (button.selected) {

            NSLog(@"selected");

            button.backgroundColor = [UIColor lightGrayColor];

            [button setTitle:@"点我干嘛!" forState:UIControlStateNormal];

            NSLog(@"%@",button.currentTitle);

        } else {

            NSLog(@"unSelected");

            [button setTitle:@"呵呵..." forState:UIControlStateNormal];

            NSLog(@"%@",button.currentTitle);

        }

    }

    ---恢复内容结束---

  • 相关阅读:
    最全的静态网站生成器(开源项目)
    移动互联网流量变现模式调研问卷
    公众平台商户接入(微信支付)功能申请教程
    微信支付全面开放
    百度天气预报接口
    微信公众平台开发(83) 生成带参数二维码
    微信支付接口申请指南
    微信自媒体账号涉违规大规模被封
    php大文件上传解决方案支持分片断点上传
    html5大文件上传解决方案(500M以上)
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4694038.html
Copyright © 2011-2022 走看看