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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容