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

        }

    }

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

  • 相关阅读:
    【数学】三分法
    【数学】【背包】【NOIP2018】P5020 货币系统
    【数学】【CF27E】 Number With The Given Amount Of Divisors
    【单调队列】【P3957】 跳房子
    【极值问题】【CF33C】 Wonderful Randomized Sum
    【DP】【CF31E】 TV Game
    【神仙题】【CF28D】 Don't fear, DravDe is kind
    【线段树】【CF19D】 Points
    【字符串】KMP字符串匹配
    【二维树状数组】【CF10D】 LCIS
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4694038.html
Copyright © 2011-2022 走看看