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);

        }

    }

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

  • 相关阅读:
    11个Linux基础面试问题
    OSI模型
    戴文的Linux内核专题:10配置内核(6)
    面向对象实验四(输入输出流)
    计算机程序的思维逻辑 (2)
    计算机程序的思维逻辑 (1)
    java基础3.0:Java常用API
    java基础2.0:Object、Class、克隆、异常编程
    java基础1.0::Java面向对象、面向对象封装、抽象类、接口、static、final
    Ajax工作原理(转)
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4694038.html
Copyright © 2011-2022 走看看