Day.02.24 UIButton

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    /*
     
        UIButton 按钮
     */

    //1.创建
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(20, 60, 100, 50)];
    
    //2.显示
    [self.view addSubview:button];
    
    //3.属性
    button.backgroundColor = [UIColor lightGrayColor];
    
        //①.按钮标题
    [button setTitle:@"一般" forState:UIControlStateNormal];
    
    [button setTitle:@"高亮" forState:UIControlStateHighlighted];
    
    [button setTitle:@"选中" forState:UIControlStateSelected];
    
            //按钮标题字体
    button.titleLabel.font = [UIFont systemFontOfSize:30];
    
        //②.按钮颜色
    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    
    [button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];
    
    [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    
        //③.按钮图片
    UIImage *image = [UIImage imageNamed:@"back_on"];
    
    [button setImage:image forState:UIControlStateNormal];
    
    
        //④.偏移
    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, -100, 0, 0)];
    
            //选中状态:系统默认NO
    button.selected = NO;
    
            //使用状态:系统默认YES
//    button.enabled = NO;// NO --> Disabled
    
    //4.方法
    
        //添加事件
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}

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

    button.selected = ! button.selected;
    
    NSLog(@"code按钮点击");
}

- (IBAction)tap:(id)sender {
    
    /*
     
        id类型
        
        button 按钮类型
     */
    
//    sender.backgroundColor = [UIColor blackColor];
    
    NSLog(@"xib 文件按钮点击");
    
//改变按钮的选中状态
botton.selected = NO;

//是否响应触摸事件
button.userInteractionEnabled = NO;

}

@end


2016-02-24 21:43:01.605 UIButton[2804:338048] xib 文件按钮点击


button //按钮
Touch Up inside //按下向上的一瞬间,用的比较多
Title //标题
state //状态
selected //已选中,勾选状态
屏幕快照 2016-02-24 下午9.42.24.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容