史上最简单的侧滑栏菜单

对于侧滑栏,相信很多人都用过,下面我将用最简单的方法实现一下,侧滑栏菜单:

HYXSideBar *hyxsidebar = [[HYXSideBar alloc] init];
    hyxsidebar.delegate = self;
    hyxsidebar.dataArray = self.dataArray;
    [hyxsidebar callSideBarIn:self];

已经创建好了一个侧滑栏菜单,如图:

侧滑栏.gif

并且,该侧滑栏菜单拥有UITableView的所有属性,可以通过代理方法一一调用

/**
 获取相应组里面的行数

 @param tableView sidebar里面的tableview
 @param section 第几组
 @return 返回的行数
 */
- (NSInteger)SideBar:( UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

/**
 cell的点击事件

 @param tableView sidebar
 @param indexPath 点击的cell位置
 */
- (void)SideBar:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
/**
 header的点击事件
 
 @param tableView sidebar
 @param index 点击的header的位置
 */
- (void)SideBar:(UITableView *)tableView didSelectHeaderAtIndex:(NSInteger )index;
/**
 得到相应的cell(也是可以随意自定义的)
 
 @param tableView sidebar里面的tableview
 @param indexPath 相应位置里面的
 @return 返回需要的cell
 */
- (UITableViewCell *)SideBar:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

/**
 总组数

 @param tableView SideBar
 @return 返回的总组数
 */
- (NSInteger)numberOfSectionsInSideBar:(UITableView *)tableView;

/**
 每一组的header名称

 @param tableView sidebar
 @param section 相应的组序列
 @return  组的名称
 */
- (NSString *)SideBar:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;

/**
 每一组的footer的名称

 @param tableView sidebar
 @param section 相应的组序列
 @return 每一组的footer名称
 */
- (NSString *)SideBar:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

/**
 cell生命周期,将要描绘出来

 @param tableView sidebar
 @param cell 将要描绘的cell
 @param indexPath cell的位置
 */
- (void)SideBar:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

/**
 cell的高度

 @param tableView sidebar
 @param indexPath cell的位置
 @return 返回的cell的高度
 */
- (CGFloat)SideBar:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

/**
 Header的高度

 @param tableView sidebar
 @param section 组
 @return 高度
 */
- (CGFloat)SideBar:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

/**
 footer的高度
 
 @param tableView sidebar
 @param section 组
 @return 高度
 */
- (CGFloat)SideBar:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

/**
 返回一个描述header的view

 @param tableView sidebar
 @param section 相应的组别
 @return 返回的viwe
 */
- (UIView *)SideBar:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
/**
 返回一个描述header的view
 
 @param tableView sidebar
 @param section 相应的组别
 @return 返回的viwe
 */
- (UIView *)SideBar:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
如此就可以对侧边栏进行个性化设置了。

奉上demo:史上最简单的侧边栏

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,303评论 4 61
  • 小时候,家里很穷。 我小时候的家是一间江南独有的地主豪宅。我只记得那房子很深,中间有一个很大的天井,天井下放了一口...
    八田草阅读 2,112评论 18 33
  • 人,不论美丑,平安健康就好;天,不论阴晴,心情愉悦就好;路,不论远近,坚持走完就好;情,不论淡浓,真心相待就好。生...
    映卿阅读 220评论 0 0
  • 儿童节快到了。跟4岁的小侄女视频,对话如下: 我:朵朵想姑姑没有哇~ 朵:不想不想 我: /palmface 那算...
    浣丛素手阅读 154评论 0 0
  • 我的闺蜜身材很好,容貌也是绝佳,每次都是带妆出门,引得路人纷纷回头。她可谓是幸运儿,身边不乏各种追求者。前几天和我...
    老绥远Richard阅读 420评论 0 0