WKCBaseUI 0.2.4

WKCBaseUI 0.2.4

Maintained by yang666.



WKCBaseUI 0.2.4

  • By
  • WeiKunChao

WKCBaseUI

Carthage compatible CocoaPods compatible License: MIT

Some base on BaseUI

  • BaseUI内的文件均单独存在,需要哪个,引入相应的头文件即可.

Such as

TableView

import into #import <WKCBaseUI/WKCBaseTableView.h>

  • 基本类背景色白色,没有多余的分割线,超出数据范围仍可滑动.
  • 可以设置分割线插入的距离.
  • 可以设置下拉刷新及上拉刷新(封装MJRefresh).
  • 可以设置row、header、footer自适应高度.
  • 修补背景色(或图).
  • 如要使用,使用的tableView继承自WKCBaseTableView即可.
  1. 自适应cell(row,其他同理)
  • [step] 设置可以自适应.
_tableView.isAutoRowHeight = YES;
  • [step] 在代理方法 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];
}
  • [step] 不能再调用tableView:heightForRowAtIndexPath:,否则仍然是定高.
  1. 设置分割线位置
  • 设置分割线的嵌入位置.
  • [step] 在控制器加载视图后的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 into #import <WKCBaseUI/WKCBaseCollectionView.h>

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

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

TarBarController(下方适用于纯代码)

import into #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. 默认push时隐藏底部bar,如不想隐藏,相应控制器内调用系统方法hidesBottomBarWhenPushed即可.
- (BOOL)hidesBottomBarWhenPushed {
return NO;
}
  1. 适用于凸图,不用额外添加任何操作.会自动根据添加图片的尺寸,自适应位置. Alt text

NavigationViewController

import into #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 into #import <WKCBaseUI/WKCBaseViewController.h>

  • 可判断跳转方式,push还是present?
  • 是否隐藏导航栏? 若想隐藏导航栏,相应控制器内调用shouldNavigationBarHiddien方法即可.
- (BOOL)shouldNavigationBarHiddien {
    return YES;
}