UIKit 框架之UIButton

列举几个稍微难点的属性,其他的方法属性都好理解,可以参照UIButton.h

//

//  ViewController.m

//  UIButton

//

//  Created by City--Online on 15/5/19.

//  Copyright (c) 2015年 XQB. All rights reserved.

//



#import "ViewController.h"



@interface ViewController ()

@property(nonatomic,strong) UIButton *btn1;

@end



@implementation ViewController



- (void)viewDidLoad {

    [super viewDidLoad];

    

    

//    typedef NS_ENUM(NSInteger, UIButtonType) {

//        UIButtonTypeCustom = 0,                         // no button type

//        UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // standard system button

//        

//        UIButtonTypeDetailDisclosure,

//        UIButtonTypeInfoLight,

//        UIButtonTypeInfoDark,

//        UIButtonTypeContactAdd,

//        

//        UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead

//    };

    _btn1=[UIButton buttonWithType:UIButtonTypeSystem];

    //确定按钮高亮时是否改变阴影的Bool值.默认时NO,当为YES时,阴影在雕刻与浮雕感之间变化(差不多就是去正常offset的相反数作为新的offset)

     _btn1.reversesTitleShadowWhenHighlighted=YES;

    

    //EdgeInsets边缘填充 类似CSS盒子模型中的内边距padding

    _btn1.imageEdgeInsets=UIEdgeInsetsMake(30, 10, 0, 0);

    _btn1.contentEdgeInsets=UIEdgeInsetsMake(30, 40, 0, 0);

    _btn1.titleEdgeInsets=UIEdgeInsetsMake(20, 20, 0, 0);

    UIImage *img=[UIImage imageNamed:@"1.jpg"];

    //UIButton里面包含一个UILabel和一个UIImageView

    [_btn1 setImage:img forState:UIControlStateNormal];

    [_btn1 setTitle:@"按钮" forState:UIControlStateNormal];

    

    //设置控件内容水平对齐方式

    _btn1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;

    

    //确定当按钮高亮时图片是否改变的BOOL值,为真时图片随按钮高亮而高亮

//    _btn1.highlighted=YES;

    _btn1.adjustsImageWhenHighlighted=YES;

    

    //确定当按钮高亮时图片是否改变的BOOL值,为真时图片随按钮失效而变暗

//    _btn1.enabled=NO;

    _btn1.adjustsImageWhenDisabled=YES;

    

    //控制当按钮按下时是否闪光的BOOL值.默认NO,YES时按下会有白色光点.图片和按钮事件的不会因闪光改变.

    _btn1.showsTouchWhenHighlighted=YES;

    _btn1.frame=CGRectMake(20, 100, 200, 200);

    _btn1.backgroundColor=[UIColor redColor];

    [self.view addSubview:_btn1];

    

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end

 UIKit 框架之UIButton

你可能感兴趣的:(UIButton)