HYCreateViewTool 1.0.0

HYCreateViewTool 1.0.0

Maintained by slagslag.



  • By
  • slagslag

HYCreateViewTool

便捷创建 UIView 及其子类. 详见 HYCreateViewTool.h

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

HYCreateViewTool is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'HYCreateViewTool'

Author

slagslag, [email protected]

Instructions

颜色可传 UIColor 或 @"0xF0F", @"66ccff", @"#66CCFF88" 按钮图片可传 UIImage 或者 UIColor 或者 色值字符

  1. UIView 通用方法
// 初始化
UIView.add(CGRectMake(0, 0, 10, 10))
UIView.init
UIView.new

// 通用设置
.rect(CGRectMake(0, 0, 10, 10)) // 位置
.backColor([UIColor redColor])  // 背景颜色
.borderWidth(2)                 // 边框宽度
.borderColor([UIColor blackColor])// 边框颜色
.cornerRadius(5)                // 圆角
.superView(self.view)            // 添加到父视图
.targetSel(self, @selector(login))// 绑定事件
.clickedBlock = ^(UIView *view) {// 绑定事件回调

};

UILabel

// 初始化
UILabel.add(CGRectMake(0, 0, 10, 10))
UILabel.init
UILabel.new

.title(@"标题") // 文字
.titleColor([UIColor redColor]) // 文字颜色
.fontSize(15) // 字体大小
.UIFont([UIFont boloSystemFontOfSize:20])// 字体
.aligment(NSTextAlignmentCenter) // 对齐方式
.lines(0) // 行数

UIButton

// 初始化
UIButton.add(CGRectMake(0, 0, 10, 10))
UIButton.init
UIButton.new

.title(@"登录") //文字
.titleState(@"未登录", UIControlStateSelected)//文字及状态
.titleColor([UIColor blackColor])//文字颜色
.titleColorState([UIColor redColor], UIControlStateSelected)//文字颜色及状态
.fontSize(18)//文字大小
.UIFont([UIFont boloSystemFontOfSize:20])//字体
.image([UIImage imageNamed:@"aa"], UIControlStateNormal)//前景图片及状态
.backImage([UIImage imageNamed:@"back"], UIControlStateNormal)//背景图片及状态
.verticalAlignment(UIControlContentVerticalAlignmentTop)//垂直对齐方式
.horizontalAlignment(UIControlContentHorizontalAlignmentLeft)//水平对齐方式
.targetSelEvent(self, @selector(login), UIControlEventValueChanged)//事件绑定

UIImageView

// 初始化
UIImageView.add(CGRectMake(0, 0, 10, 10))
UIImageView.init
UIImageView.new

.hy_image([UIImage imageNamed:@"lyf"]) //图片
.hy_imageDefaultMode([UIImage imageNamed:@"lyf"]) //默认填充模式下设置图片
.mode(UIViewContentModeScaleAspectFill)//填充模式

UITableView

1.初始化

// 初始化不注册cell
+ (instancetype)addTabeView:(CGRect)rect style:(UITableViewStyle)style delegate:(id)delegate backColor:(id)backColor superView:(UIView * _Nullable)superView;

// 初始化并注册cell
+ (instancetype)addTabeView:(CGRect)rect style:(UITableViewStyle)style delegate:(id)delegate backColor:(id)backColor superView:(UIView * _Nullable)superView cells:(NSString *)cells,...

2.注册 cell

- (void)registerCells:(NSString *)cells,...;

// Example:
[self.tableView registerCells:@"HYTableViewCell",@"HYHomeTableViewCell",nil];

3.注册 headerFooter

- (void)registerHeaderFooters:(NSString *)headerFooters,...;

// Example:
[self.tableView registerHeaderFooters:@"HYTableViewHeader",@"HYTableViewFooter",nil];

UICollectionView

  1. 初始化
// 初始化不注册 cell
+ (instancetype)addCollectionView:(CGRect)rect layout:(UICollectionViewLayout *)layout delegate:(id)delegate backColor:(id)backColor superView:(UIView * _Nullable)superView;

// 初始化并注册cell
+ (instancetype)addCollectionView:(CGRect)rect layout:(UICollectionViewLayout * _Nonnull)layout delegate:(id)delegate backColor:(id)backColor superView:(UIView * _Nullable)superView cells:(NSString *)cells,...;

2.注册 cell

- (void)registerCells:(NSString *)cells,...;

// Example:
[self.collectionView registerCells:@"HYCollectionViewCell",@"HYHomeCollectionViewCell",nil];

3.注册 header

- (void)registerHeaders:(NSString *)cells,...;

// Example:
[self.collectionView registerHeaders:@"HYCollectionViewHeader",@"HYHomeCollectionViewHeader",nil];

4.注册 footer

- (void)registerFooters:(NSString *)cells,...;

// Example:
[self.collectionView registerFooters:@"HYCollectionViewFooter",@"HYHomeCollectionViewFooter",nil];

UITableViewCell 使用该方法不需要提前注册 cell

// 默认 cell 模式创建并复用 cell
+ (instancetype)dequeueReusableCellWithTableView:(UITableView * _Nonnull)tableView;

// 创建并复用 cell
+ (instancetype)dequeueReusableCellWithTableView:(UITableView * _Nonnull)tableView  cellStyle:(UITableViewCellStyle)style;;

// Example:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MineTableViewCell *cell = [MineTableViewCell dequeueReusableCellWithTableView:tableView];
return cell;
}

// Example:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MineTableViewCell *cell = [MineTableViewCell dequeueReusableCellWithTableView:tableView cellStyle:(UITableViewCellStyleSubtitle)];
return cell;
}