zeR0Lu / BAButton

自定义button

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BAButton

自定义button

开发中如有问题,可以联系本人

新浪微博:@博爱1616

QQ: 137361770

对pod还是不熟的同学,可以看下我的博客,是最新的pod安装和使用方法,

http://www.cnblogs.com/boai/p/4977976.html

更新记录:

2016.12.4 -

pod 最新上架,修复部分已知bug,代码更精简!

###示例展示:

image image

##完全实现button的自定义,

###pod 导入: pod 'BAButton', '~> 2.0.1' 如果发现pod search BAButton 搜索出来的不是最新版本,需要在终端执行cd转换文件路径命令退回到desktop,然后执行pod setup命令更新本地spec缓存(可能需要几分钟),然后再搜索就可以了 具体步骤:

  • pod setup : 初始化
  • pod repo update : 更新仓库
  • pod search BAButton

###项目中导入头文件:

#import <BAButton.h> 即可
typedef NS_ENUM(NSUInteger, BAButtonStatus) {
    BAButtonStatusNormal, // 默认
    BAButtonStatusLeft, // 左对齐
    BAButtonStatusCenter, // 居中对齐
    BAButtonStatusRight, // 右对齐
    BAButtonStatusTop, // 图标在上,文本在下(居中)
    BAButtonStatusBottom, // 图标在下,文本在上(居中)
};


// 大家下载demo后可能出现图片不显示,只需更换图片即可,注意button的frame哦!
// 此外,此button的titleLAbel只支持一行显示,不支持多行!敬请注意!

// 示例1:
BAButton *btn1 = [[BAButton alloc] init];
[btn1 setBackgroundColor:[UIColor greenColor]];
[btn1 setImage:[UIImage imageNamed:@"播放次数"] forState:UIControlStateNormal];
[btn1 setTitle:@"左对齐[文字左图片右]" forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn1.buttonStatus = BAButtonStatusLeft;
btn1.buttonCornerRadius = 5.0;
btn1.titleLabel.font = [UIFont systemFontOfSize:15];
btn1.frame = CGRectMake(CGRectGetMinX(btn.frame), CGRectGetMaxY(btn.frame) + 10, 200, 50);
[self.view addSubview:btn1];

// 示例2:
BAButton *btn5 = [[BAButton alloc] init];
btn5.buttonStatus = BAButtonStatusTop;
[btn5 setBackgroundColor:[UIColor greenColor]];
[btn5 setImage:[UIImage imageNamed:@"播放次数"] forState:UIControlStateNormal];
[btn5 setTitle:@"图片在上,文字在下" forState:UIControlStateNormal];
btn5.titleLabel.font = [UIFont systemFontOfSize:10];
btn5.buttonCornerRadius = 5.0;
[btn5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn5.frame = CGRectMake(CGRectGetMinX(btn.frame), CGRectGetMaxY(btn4.frame) + 10, 200, 80);
[self.view addSubview:btn5];

其他示例可下载demo查看源码!

About

自定义button

License:MIT License


Languages

Language:Objective-C 98.7%Language:Ruby 1.3%