UIButton常用属性介绍lzp


  1. //这里创建自定义的按钮  
  2. UIButton *buttonExample = [UIButton buttonWithType:UIButtonTypeCustom];    
  3. //    button类型有以下6种,  
  4. //    typedef enum {  
  5. //        UIButtonTypeCustom,          自定义风格  
  6. //        UIButtonTypeRoundedRect,         圆角矩形   
  7. //        UIButtonTypeDetailDisclosure,    蓝色小箭头按钮,主要做详细说明用  
  8. //        UIButtonTypeInfoLight,           亮色感叹号  
  9. //        UIButtonTypeInfoDark,            暗色感叹号  
  10. //        UIButtonTypeContactAdd,          十字加号按钮  
  11. //    } UIButtonType;  
  12.       
  13. //位置  
  14. buttonExample.frame = CGRectMake(0, 100, 100, 40);  
  15.    
  16. //背景色  
  17. buttonExample.backgroundColor = [UIColor clearColor];  
  18.       
  19. //填充图片
  20. [buttonExample setImage:[UIImage imageNamed:@"pig.png"] forState:UIControlStateNormal];
  21.     
  22. //背景图片
  23. [buttonExample setBackgroundImage:[UIImage imageNamed:@"pig.png"] forState:UIControlStateNormal];      
  24.       
  25. //标题  
  26. [buttonExample setTitle:@"点击" forState:UIControlStateNormal];  
  27.       
  28. //forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现  
  29. //    enum {  
  30. //        UIControlStateNormal    常规状态显现                
  31. //        UIControlStateHighlighted   高亮状态显现      
  32. //        UIControlStateDisabled   禁用的状态才会显现  
  33. //        UIControlStateSelected    选中状态                
  34. //        UIControlStateApplication, 当应用程序标志时              
  35. //        UIControlStateReserved  为内部框架预留,可以不管他               
  36. //    };  
  37.       
  38. //禁用高亮状态
  39. buttonExample.adjustsImageWhenHighlighted = NO;  

  40. //高亮状态
  41. buttonExample.showsTouchWhenHighlighted = YES;  

  42. //圆角
  43. headLogoButton.layer.masksToBounds = YES;
  44. headLogoButton.layer.cornerRadius = headLogoButton.frame.size.width/2;

  45. //添加事件 action:方法 forControlEvents:什么时候执行
  46. [buttonExample addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];

  47. //添加
  48. [self.view addSubview:buttonExample];  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值