项目作者: LiuShuoyu

项目描述 :
继承UIButton,重写layoutSubviews,改变UIButton的imageView和titleLabel的的frame。可以任意该改变UIButtonimageView和titleLabel的的起始位置和中间距离。通过枚举,imageVIew和titleLabel分为上下,左右排列布局。
高级语言: Objective-C
项目地址: git://github.com/LiuShuoyu/UIFrameButton.git
创建时间: 2016-10-03T15:37:31Z
项目社区:https://github.com/LiuShuoyu/UIFrameButton

开源协议:MIT License

下载


UIFrameButton介绍?

  • 继承UIButton,重写layoutSubviews,改变UIButton的imageView和titleLabel的的frame。可以任意该改变UIButtonimageView和titleLabel的的起始位置和中间距离。通过枚举,imageVIew和titleLabel分为上下,左右排列布局

界面样式

  1. typedef NS_ENUM(NSInteger, UIButtonFrameSttyle)
  2. {
  3. LeftImageWithRightTitleFrameStyle=0,
  4. LeftTitleWithRightImageFrameStyle,
  5. TopImageWithbuttomTitleFrameStyle,
  6. TopTitleWithbuttomImageFrameStyle,
  7. };

代码

  1. UIFrameButton *btn =({
  2. UIFrameButton *newBtn=[[UIFrameButton alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
  3. [newBtn addTarget:self action:@selector(clikBtn:) forControlEvents:UIControlEventTouchUpInside];
  4. newBtn.center =self.view.center;
  5. [newBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  6. [newBtn setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
  7. [newBtn setImage:[UIImage imageNamed:@"play"] forState:UIControlStateHighlighted];
  8. [newBtn setTitle:@"点击我,我开始移动" forState:UIControlStateNormal];
  9. newBtn.frameStyle =LeftImageWithRightTitleFrameStyle;
  10. newBtn.beginDistance =1;
  11. newBtn.layer.borderColor = [UIColor grayColor].CGColor;
  12. newBtn.layer.cornerRadius = 5;
  13. newBtn.layer.borderWidth =1;
  14. newBtn.layer.masksToBounds =YES;
  15. newBtn;
  16. });
  17. btn.frameStyle =TopImageWithbuttomTitleFrameStyle; //设置布局样式
  18. btn.centerDistance =5//设置image和title的距离
  19. btn.beginDistance = 5 //设置subViews的开始的距离

有问题反馈

在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流

发布到cocoapods

*pod ‘UIFrameButton’, ‘~> 1.0’