WKCBaseUI 0.2.4

WKCBaseUI 0.2.4

yang666 维护。



WKCBaseUI 0.2.4

  • 作者
  • WeiKunChao

WKCBaseUI

Carthage compatible CocoaPods compatible License: MIT

基于 BaseUI

  • BaseUI 中的文件都是独立的,需要哪个,就引入相应的头文件即可。

例如

TableView

导入 #import <WKCBaseUI/WKCBaseTableView.h>

  • 基本类背景色为白色,没有多余的分割线,超出数据范围仍可滑动。
  • 可以设置分割线插入的距离。
  • 可以设置下拉刷新及上拉刷新(封装 MJRefresh)。
  • 可以设置 row、header、footer 自适应高度。
  • 修补背景色(或图)。
  • 如要使用,使用的 tableView 继承自 WKCBaseTableView 即可。
  1. 自适应 cell(row,其他同理)
  • [步骤] 设置可以自适应。
_tableView.isAutoRowHeight = YES;
  • [步骤] 在代理方法 tableView:willDisplayCell:forRowAtIndexPath: 和 tableView:estimatedHeightForRowAtIndexPath: 中分别缓存和读取高度。
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self.tableView readRowHeightAtIndexPath:indexPath];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView saveRowHeightWithCell:cell atIndexPath:indexPath];
}
  • [步骤] 不能再调用 tableView:heightForRowAtIndexPath:,否则仍然是定高。
  1. 设置分割线位置
  • 设置分割线的嵌入位置。
  • [步骤] 在控制器加载视图后的 viewDidLayoutSubviews 方法中和 tableView 代理 tableView:willDisplayCell:forRowAtIndexPath: 方法中均设置。
[self.tableView setUpSeparatorInsert:UIEdgeInsetsMake(0, 50, 0, 50)];

Alt text

  1. 刷新(以下拉为例)

普通类型:有箭头、有时间、有下拉状态提示。

__weak typeof(self)weakSelf = self;
[_tableView setUpBaseHeaderRefresh:^{
[weakSelf.tableView.mj_header endRefreshing];
}];

只有菊花,可以设置菊花类型。(Gray, white 以及 largeWhite)

__weak typeof(self)weakSelf = self;
[_tableView setUpIndicatorHeaderRefreshWithIndicatorStyle:UIActivityIndicatorViewStyleGray completionHandle:^{
[weakSelf.tableView.mj_header endRefreshing];
}];

自定义图片的(可以是动图)

__weak typeof(self)weakSelf = self;
[_tableView setUpImageHeaderRefreshWithImages:@[[UIImage imageNamed:@"rectangle15Copy5"]] completionHandle:^{
[weakSelf.tableView.mj_header endRefreshing];
}];

修补背景(可直接添加背景色或是图片)

 [self.tableView setUpScrollViewWithColor:[UIColor blueColor]];

Alt text

CollectionView

导入 #import <WKCBaseUI/WKCBaseCollectionView.h>

  • 基本类背景色为白色。
  • 可以设置下拉刷新及上拉刷新(封装 MJRefresh)。
  • 如要使用,使用的 collectionView 继承自 WKCBaseCollectionView 即可。

方法同 TableView。(只在竖直方向滚动时有效)

TabBarController(下方适用于纯代码)

导入到 #import <WKCBaseUI/WKCBaseTabBarController.h>

  • 快速搭建整体结构。
  • 可以在tabBar对象中设置导航栏基本信息,包括背景色、返回按钮、标题属性等。
  • 提供了三种返回样式:白色、黑色以及灰色。其他样式可以自定义。
  • 控制器模型,整合单独控制器的所有信息。
  • 适用于图片超出(凸图)。
  1. 创建控制器模型。
- (WKCBaseViewControllerModel *)main {
if (!_main) {
WKCMainViewController *controller = [WKCMainViewController new];
NSString *title = @"主页";
UIImage *normalImage = [UIImage imageNamed:@"Tab_Mine_Normal"];
UIImage * selectedImage = [UIImage imageNamed:@"Tab_Main_Selected"];
NSDictionary *attributedNoramlTitle = @{NSForegroundColorAttributeName: [UIColor blackColor],NSFontAttributeName: [UIFont systemFontOfSize:15]};
NSDictionary *attributedSelectedTitle = @{NSForegroundColorAttributeName: [UIColor blueColor],NSFontAttributeName: [UIFont boldSystemFontOfSize:17]};
_main = [[WKCBaseViewControllerModel alloc] initWithDictionary:@{@"controller":controller,@"title":title,@"normalImage":normalImage,@"selectedImage":selectedImage,@"attributedNoramlTitle":attributedNoramlTitle,@"attributedSelectedTitle":attributedSelectedTitle}];
}
return _main;
}
  1. 快速加载。
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor clearColor];
WKCBaseTabBarController *tabBarController =  [WKCBaseTabBarController new];
tabBarController.bgColor = [UIColor yellowColor];
tabBarController.navigationBgColor = [UIColor redColor];
tabBarController.navigationType = navigationbackTypeWhite;
[tabBarController setUpChildsWithModel:self.main,self.classroom,self.community,self.shopping,self.mine, nil];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
  1. 这里设置的属性适用于所有控制器。如果某个控制器需要特殊设置,可以在其内部单独更改。
  2. 默认推送时隐藏底部栏。如果不想隐藏,可以在相应控制器中调用系统方法hidesBottomBarWhenPushed。
- (BOOL)hidesBottomBarWhenPushed {
return NO;
}
  1. 适用于凸图,不需要额外操作。会自动根据添加图片的尺寸,自适应位置。[图片](https://github.com/WeiKunChao/WKCBaseUI/raw/master/screenShort/7.png)

NavigationViewController

导入到 #import <WKCBaseUI/WKCBaseNavigationViewController.h>

  • 可以设置背景色。
  • 可以设置标题属性。
  • 可以设置返回按钮。如果单独使用navigationViewController,初始化方法仍然使用系统方法。
@property (nonatomic, strong) UIColor * bgColor;
@property (nonatomic, strong) NSDictionary <NSAttributedStringKey,id>* attributedDictionary;
@property (nonatomic, strong) UIBarButtonItem * leftBarButtonItem;
@property (nonatomic, assign) navigationbackType navigationType;

ViewController

导入到 #import <WKCBaseUI/WKCBaseViewController.h>

  • 可以判断跳转方式,是push还是present?
  • 是否隐藏导航栏?如果想隐藏导航栏,可以在相应控制器中调用shouldNavigationBarHiddien方法。
- (BOOL)shouldNavigationBarHiddien {
    return YES;
}