iOS UITextField便利构造器(初始化方法)

UITextField+KKInitializer 简介


本文使用category重写了UITextField的一些常用属性设置方法,
采用链式语法,优化代码、提高编程效率。

这是一系列UI控件便利构造方法中的一个, 用pod管理,方便自己和他人使用。

Cocoapods


pod 'KKInitializer/UITextField+KKInitializer'

代码示例


UITextField *textField = UITextField.k_initFrame(CGRectMake(100, 100, 200, 40));
textField.k_placeholder(@"占位占位占位").k_borderStyle(UITextBorderStyleRoundedRect).k_textColor(UIColor.redColor).k_fontSize(20.f);
[self.view addSubview:textField];

相关链接


Github: https://github.com/cocoZ/KKInitializer

KKInitializer: https://www.jianshu.com/p/e6ef1df5dd9a

UITextField+KKInitializer接口


@interface UITextField (KKInitializer)

+ (UITextField *(^)(void))k_init;
+ (UITextField *(^)(CGRect frame))k_initFrame;
- (UITextField *(^)(CGRect frame))k_frame;

- (UITextField *(^)(NSString *text))k_text;
- (UITextField *(^)(NSString *placeholder))k_placeholder;
- (UITextField *(^)(UIColor *textColor))k_textColor;

///  systom font
- (UITextField *(^)(CGFloat fontSize))k_fontSize;
- (UITextField *(^)(CGFloat boldFontSize))k_boldFontSize;
- (UITextField *(^)(UIFont *font))k_font;

- (UITextField *(^)(NSTextAlignment alignment))k_textAlignment;
- (UITextField *(^)(UITextBorderStyle style))k_borderStyle;
@end

你可能感兴趣的:(iOS UITextField便利构造器(初始化方法))