PPiAwesomeButton

https://github.com/pepibumur/PPiAwesomeButton

UIButton category with new methods to setup a button with text + FontAwesome Icon. Open App

UIButton的category,添加了新的方法,用文本格式的图标设置button.

Updates - 更新

28 -June-2014 - Cocoapods version - 1.3.7
  • Updated demo project that didn't work due to UIView+Autolayout category 更新了demo项目解决了这个category不能工作的问题
26-March-2014 - Cocoapods version - 1.3.7

Added the feature to set the icon passing an UIImageView 添加了新的属性,可以用UIImageView来设置icon

-(void)setIconImageView:(UIImageView *)iconImageView;

Fixed issue related with vertical size of subviews 修复了部分的bug

25-March-2014 - Cocoapods version - 1.3.7

Added the possibility to set the icon in UIImage format. The way to do that is just using the methods:

+(UIAwesomeButton*)buttonWithType:(UIButtonType)type text:(NSString *)text icon:(NSString *)icon attributes:(NSDictionary *)attributes andIconPosition:(IconPosition)position;
-(id)initWithFrame:(CGRect)frame text:(NSString *)text iconImage:(UIImage *)icon attributes:(NSDictionary *)attributes andIconPosition:(IconPosition)position;

Features - 特性

  • Background color can be setup dependending on the UIButton State thanks to its new method:-(void)setBackgroundColor:(UIColor*)color forUIControlState:(UIControlState)state;
  • UIButton can be initialized using following +(UIButton*)buttonWithType:(UIButtonType)type text:(NSString*)text icon:(NSString*)icon textAttributes:(NSDictionary*)attributes andIconPosition:(IconPosition)position; -(id)initWithFrame:(CGRect)frame text:(NSString*)text icon:(NSString*)icon textAttributes:(NSDictionary*)attributes andIconPosition:(IconPosition)position; where you can specify text/icon attributes using an NSDictionary ( you'll find more information in Apple Documentation. Moreover you can specify position of Icon inside UIButton thanks to parameter IconPosition (Left or Right ))
  • Anytime you can change following properties of UIButton: textAttributes--(void)setTextAttributes:(NSDictionary*)attributes forUIControlState:(UIControlState)state; backgroundColor--(void)setBackgroundColor:(UIColor*)color forUIControlState:(UIControlState)state; iconPosition--(void)setIconPosition:(IconPosition)position; buttonText--(void)setButtonText:(NSString*)text;buttonIcon--(void)setButtonIcon:(NSString*)icon; buttonRadius--(void)setRadius:(CGFloat)radius;
  • 可以设置UIButton的背景颜色
  • UIButton可以通过简易的方法来设置
  • 任何时候,你都可以设置UIButton的以下属性

Install - 安装

The easiest way to install PPiAwesomeButton is using CocoaPods:

1) Add the pod to podfile

pod 'PPiAwesomeButton'
pod 'FontAwesome+iOS', :git => 'git@github.com:alexdrone/ios-fontawesome.git'

2) Refresh your project pods pod install

3) Add awesome font to your Info.plists setting UIAppFonts entry as array and addingFontAwesome.ttf to this array.

Example of using - 使用示例

Here is an example of using for generate an UIButton with Twitter design

下面是一个例子,用来生成Twitter设计样式的UIButton

UIButton *twitter1=[UIButton buttonWithType:UIButtonTypeCustom text:@"Twitter" icon:@"icon-twitter" textAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor whiteColor]} andIconPosition:IconPositionLeft];
[twitter1 setBackgroundColor:[UIColor colorWithRed:27.0f/255 green:178.0f/255 blue:233.0f/255 alpha:1.0] forUIControlState:UIControlStateNormal];
[twitter1 setBackgroundColor:[UIColor colorWithRed:60.0f/255 green:89.0f/255 blue:157.0f/255 alpha:1.0] forUIControlState:UIControlStateHighlighted];
twitter1.frame=CGRectMake(10, 10, 120, 44);
[twitter1 setRadius:5.0];
[self.view addSubview:twitter1];

Here another one for a Pinterest button

以下是另外一个Pinterest样式的按钮

UIButton *pinterest2=[UIButton buttonWithType:UIButtonTypeCustom text:@"Pin it!" icon:@"icon-pinterest" textAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:32],NSForegroundColorAttributeName:[UIColor whiteColor]} andIconPosition:IconPositionLeft];
[pinterest2 setBackgroundColor:[UIColor colorWithRed:205.0f/255 green:35.0f/255 blue:44.0f/255 alpha:1.0] forUIControlState:UIControlStateNormal];
[pinterest2 setBackgroundColor:[UIColor colorWithRed:244.0f/255 green:61.0f/255 blue:91.0f/255 alpha:1.0] forUIControlState:UIControlStateHighlighted]; pinterest2.frame=CGRectMake(10, 270, 280, 50);
[pinterest2 setRadius:0.0];
[self.view addSubview:pinterest2];

And for Facetime too:

以及Facetime样式的按钮

UIButton *facetime1=[UIButton buttonWithType:UIButtonTypeCustom text:@"Facetime" icon:@"icon-facetime-video" textAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor whiteColor]} andIconPosition:IconPositionRight];
[facetime1 setBackgroundColor:[UIColor colorWithRed:40.0f/255 green:219.0f/255 blue:31.0f/255 alpha:1.0] forUIControlState:UIControlStateNormal];
facetime1.frame=CGRectMake(10, 160, 120, 44);
[facetime1 setRadius:22.0];
[self.view addSubview:facetime1];

 

--- Extra - UIAwesomeButton ---

If you've detected some misalignments in icon and text I've created a new class calledUIAwesomeButton (UIView subclass) that has the same behaviour an UIButton has but implemented from zero ( and without misalignments between elements ). Here's an example of implementation into your project:

如果你发现了一些未匹配的图标或者文本,我创建了一个新的类叫UIAwesomeButton(UIView的子类),它与之前的button的功能一致,但是没有实现匹配性,以下是使用示例.

UIAwesomeButton *button4 = [[UIAwesomeButton alloc] initWithFrame:CGRectMake(10, 400, 280, 50) text:@"Test" icon:nil textAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor whiteColor],@"IconFont":[UIFont fontWithName:@"fontawesome" size:40]} andIconPosition:IconPositionLeft];
[button4 setBackgroundColor:[UIColor colorWithRed:205.0f/255 green:35.0f/255 blue:44.0f/255 alpha:1.0] forUIControlState:UIControlStateNormal];
[button4 setBackgroundColor:[UIColor colorWithRed:244.0f/255 green:61.0f/255 blue:91.0f/255 alpha:1.0] forUIControlState:UIControlStateHighlighted];
[button4 setRadius:3.0];
[button4 setSeparation:10];
[button4 setTextAlignment:NSTextAlignmentLeft];
[button4 setActionBlock:^{
NSLog(@"Working!");
}];
[self.view addSubview:button4];

Screenshot - 截图

Attributed Strings : Attributes List - 富文本

Attributes that you can apply to text in an attributed string.

NSString *const NSFontAttributeName;
NSString *const NSParagraphStyleAttributeName;
NSString *const NSForegroundColorAttributeName;
NSString *const NSBackgroundColorAttributeName;
NSString *const NSLigatureAttributeName;
NSString *const NSKernAttributeName;
NSString *const NSStrikethroughStyleAttributeName;
NSString *const NSUnderlineStyleAttributeName;
NSString *const NSStrokeColorAttributeName;
NSString *const NSStrokeWidthAttributeName;
NSString *const NSShadowAttributeName;
NSString *const NSVerticalGlyphFormAttributeName;

Full list here

Font Awesome Icons - Font Awesome 图标

You'll find the list of Awesome Icons here. Each icon has an identifier that you have to use in UIButton to add an Icon to your UIButton.

你会在这里找到Awesome Icons,每一个icon都有一个id,可以在UIButton中调用.

[翻译] PPiAwesomeButton的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. maven私服配置

    1.maven私服setting.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <setting ...

  2. URL编码分析与乱码解决方案

    一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符号.比如,世界上有英文字母的网址"http://ww ...

  3. elasticsearch(一):JAVA api操作

    1.创建一个mavan项目,项目的以来配置如下. <?xml version="1.0" encoding="UTF-8"?> <projec ...

  4. Ubuntu18.0.4查看显示器型号

    在官网https://launchpad.net/ubuntu/+source/xresprobe下载二进制包,apt-get目前无法安装xresprobe 输入命令sudo ddcprobe 得到如 ...

  5. 2<<3=?

    public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(" ...

  6. 问题集录--从初级java程序员到架构师,从小工到专家

    怎样学习才能从一名Java初级程序员成长为一名合格的架构师,或者说一名合格的架构师应该有怎样的技术知识体系,这是不仅一个刚刚踏入职场的初级程序员也是工作三五年之后开始迷茫的老程序员经常会问到的问题.希 ...

  7. [转]SQL Server 2008- Get table constraints

    本文转自:https://stackoverflow.com/questions/14229277/sql-server-2008-get-table-constraints You should u ...

  8. C# 开发者审查代码的41条建议

    1. 确保没有任何警告(warnings). 2.如果先执行Code Analysis(启用所有Microsoft Rules)再消除所有警告就更好了. 3. 去掉所有没有用到的usings.编码过程 ...

  9. css3 transition(转换)笔记

    之前transition也用过,大都是ctrl+c,然后ctrl+v,没有了解太详细,这次对transition的应用源自侧边抽屉展开收起的动画效果需要. W3C标准中对css3的transition ...

  10. JSONArray排序[收藏]

    问题 JSONArray中嵌套JSONObject, 对JSONArray进行排序 排序前: [{"id":1,"name":"ljw"}, ...