lilei644 / llbootstrapbutton Goto Github PK
View Code? Open in Web Editor NEWBootstrap 3.0扁平化风格按钮,自带图标,一句代码直接调用!!!
License: MIT License
Bootstrap 3.0扁平化风格按钮,自带图标,一句代码直接调用!!!
License: MIT License
命名上,动作式函数应使用动词开头
- (void)bs_buttonDefault;
可以改进成:
- (void)bs_configureAsDefaultStyle;
同时,下面的类别方法没加前缀,且 icon
的提示词不能明确后面是个 string
- (void)textWithIcon:(NSString *)icon;
可以改进成:
- (void)bs_setTextFromIconKey:(NSString *)iconKey;
API 设计上 Button 的这些重复方法可以考虑枚举。
API 设计上给 UIButton 和 UITextView 加扩展的方式侵染性太大
比如想用这个字体且想自己控制字号的话就不得不像 Demo 这样调用,而且 Icon 的位置你只给出了前后两个选择:
UIFont *font = [UIFont systemFontOfSize:16.0f];
UIButton *iconDefault = [UIButton buttonWithType:UIButtonTypeCustom];
[iconDefault setFrame:CGRectMake(180, 50, 100, 50)];
[iconDefault setTitle:@"Default" forState:UIControlStateNormal];
[iconDefault bs_buttonDefault];
[iconDefault.titleLabel setFont:font];
[iconDefault bs_buttonAddIcon:@"fa-android" isBefore:YES];
[self.view addSubview:iconDefault];
可以以更小侵染性的方式实现,比如写俩扩展:
@interface UIFont (SunnyxxTest)
+ (instancetype)xx_awesomeFontOfSize:(CGFloat)size;
@end
@interface NSString (SunnyxxTest)
@property (nonatomic, readonly) NSString *xx_awesomeIconRepresentation;
@end
这样用起来可以简单一点,还不至于限制 Icon 位置:
UIButton *sunnyxxButton = [UIButton buttonWithType:UIButtonTypeCustom];
sunnyxxButton.titleLabel.font = [UIFont xx_awesomeFontOfSize:16];
[sunnyxxButton setTitle:[NSString stringWithFormat:@"sunny%@xx", @"fa-apple".xx_awesomeIconRepresentation] forState:UIControlStateNormal];
[self.view addSubview:sunnyxxButton];
可以的话提供一个转 UIImage 的方法是极好的
在集成上可以再内聚一点
比如搞一个 bundle 放字体,然后再 CocoaPods 上可以直接集成进来,免去拖字体的麻烦。如何在自己的 bundle 中读取自定义字体可以参考 http://stackoverflow.com/questions/14735522/can-i-embed-a-custom-font-in-a-bundle-and-access-it-from-an-ios-framework
加油,祝 iOS 开发开心~
UIFont+LLBootstrapFont.m
NSString *fontPath = [[NSBundle loadFontBundle] pathForResource:@"fontawesome-webfont" ofType:@"ttf"];
fontPath 为nil.
btn.setTitle("fa-github".bs_awesomeIconRepresentation+" 查 找", forState: UIControlState.Normal)
图标是个问号
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.