iOS UIButton属性

UIButton类型:

    UIButtonTypeCustom                 // 自定义类型  

    UIButtonTypeSystem                

    UIButtonTypeDetailDisclosure   //细节展示按钮

    UIButtonTypeInfoLight            //浅色背景的信息按钮

    UIButtonTypeInfoDark            //暗色背景的信息按钮

    UIButtonTypeContactAdd       //添加按钮

    UIButtonTypeRoundedRect = UIButtonTypeSystem    //圆角矩形

 

UIButton状态:   

    UIControlStateNormal       = 0,                //正常状态

    UIControlStateHighlighted  = 1 << 0,      //高亮状态               

    UIControlStateSelected     = 1 << 2,      //选中状态          

    UIControlStateApplication                     //

    UIControlStateReserved                       //保留状态

    UIControlStateDisabled                       //禁用状态

 

  //创建btn 

    UIButton * btn =[UIButton buttonWithType:UIButtonTypeCustom];

//坐标    

    btn.frame =CGRectMake(x, y, width, height);

//标题                                       

    [btn setTitle:@"请选择" forState:UIControlStateNormal];

//字体大小                  

    btn.titleLabel.font=[UIFont boldSystemFontOfSize:14.0f];  

//背景颜色              

    btn.backgroundColor=[UIColor lightGrayColor];  

//标题颜色                           

    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

//背景图片  

    [btn setBackgroundImage:newImage  forState:UIControlStateNormal];

//填充图片   

    [btn setImage:[UIImage imageNamed:@"btng.png"] forState:UIControlStateNormal];     

 //btn触发事件,调下一个方法

    [btn addTarget:self action:@selector(btnChu) forControlEvents:UIControlEventTouchUpInside];

 //把btn放在view上

    [self.view addSubview:btn];    

    

   /*    1 默认情况下按钮高亮,图像颜色深,如果btn.adjustsImageWhenHighlighted=NO;可以去掉这个功能

          2禁用:btn.adjustsImageWhenDisabled=NO;

          3按钮按下发亮:btn.showsTouchWhenHighlighted=YES;

   */

posted @ 2014-06-27 15:41  洛妤  阅读(203)  评论(0编辑  收藏  举报