首页 > 代码库 > WMPageController设置menuView的左右视图
WMPageController设置menuView的左右视图
效果图如下:
绿色的是自定义的emenuView的rightView哟!!!
代码实现如下:
//// CategoryVC.m// JSHui//// Created by Apple on 16/9/16.// Copyright © 2016年 桑孔桥. All rights reserved.//#import "CategoryVC.h"#import "OneVC.h"#import "TwoVC.h"#import "ThreeVC.h"#import "FourVC.h"#import "FIveVC.h"#import "SixVC.h"#import "SevenVC.h"#import "EightVC.h"#import "LNSliderView.h"#import "CategoryModel.h"#import <MJExtension.h>#import "CoverView.h"#import "WMMenuView.h"@interface CategoryVC ()<UIScrollViewDelegate,LNSliderViewDelegate,CoverViewDelegate>{ NSInteger i;}@property (strong, nonatomic) LNSliderView *sliderView;//数据源@property (strong, nonatomic) NSMutableArray *dataArr;//子控制器@property (strong, nonatomic) NSMutableArray *subsArr;@property(nonatomic,strong)UIScrollView *contentScv;@end@implementation CategoryVC-(NSMutableArray *)dataArr{ if (_dataArr == nil) { _dataArr = [NSMutableArray array]; } return _dataArr;}-(NSMutableArray *)subsArr{ if (_subsArr == nil) { _subsArr =[NSMutableArray array]; } return _subsArr;}-(void)back{ }-(void)tag{ XMGLogFunc }-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; self.title = @"类别"; self.navigationController.navigationBar.barTintColor = HexRGB(0x55b2ff); [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; self.view.backgroundColor = [UIColor whiteColor];}- (void)viewDidLoad{ [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = NO; self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTitle:@"123" target:self action:@selector(tag)]; [self getData]; self.menuBGColor = [UIColor whiteColor]; self.menuView.backgroundColor = [UIColor whiteColor]; self.menuViewStyle = WMMenuViewStyleLine; self.menuView.width = SCREEN_WIDTH - 60; self.progressColor = [UIColor redColor]; self.titleColorNormal = [UIColor blackColor]; self.titleColorSelected = [UIColor blackColor]; self.titleSizeNormal = 14; self.titleSizeSelected = 14;}- (NSArray *)titles { return @[@"丸子类",@"水产类",@"猪肉类",@"素食类",@"小吃类",@"牛羊类",@"牛羊类",@"其他类"];}#pragma mark - WMPageControllerDataSource- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController { return self.titles.count;}- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index { switch (index) { case 0: { OneVC *allVC0 = [[OneVC alloc] init]; return allVC0; } case 1: { TwoVC *allVC1 = [[TwoVC alloc] init]; return allVC1; } case 2: { ThreeVC *allVC2 = [[ThreeVC alloc] init]; return allVC2; } case 3: { FourVC *allVC3 = [[FourVC alloc] init]; return allVC3; } case 4: { FIveVC *allVC4 = [[FIveVC alloc] init]; return allVC4; } case 5: { SixVC *allVC5 = [[SixVC alloc] init]; return allVC5; } case 6: { SevenVC *allVC6 = [[SevenVC alloc] init]; return allVC6; } break; default: { OneVC *allVC7 = [[OneVC alloc] init]; return allVC7; } break; }}- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index { return self.titles[index];}- (void)pageController:(WMPageController *)pageController lazyLoadViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info { NSLog(@"%@", info);}- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {}// 请求网络数据-(void)getData{ [[NetworkSingle sharemanger]getGoodsTypeDic:nil url:@"Goods/goodstype" SuccessBlock:^(id responseBody) { NSData *data =http://www.mamicode.com/ [NSJSONSerialization dataWithJSONObject:responseBody options:NSJSONWritingPrettyPrinted error:nil]; NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"_______%@",str); self.dataArr = [CategoryModel mj_objectArrayWithKeyValuesArray:responseBody[@"data"]]; [self dealTitles]; } fail:^(NSString *error) { }];}// 请求数据更新menuView标题- (void)dealTitles{ for (NSInteger index = 0; index< self.dataArr.count; index++) { CategoryModel *model = self.dataArr[index]; // 注意: 设置rightView或者是leftView要在viewDidLoad和刷新menuView之前即可.其他设置无效 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.backgroundColor = [UIColor greenColor]; btn.frame = CGRectMake(0,0, self.menuView.height, self.menuView.height); self.menuView.rightView = btn; [self updateTitle:model.t_type_name atIndex:index]; }}@end
代码注释很详细了哟!!
注意: 如果你是在init里实现menuView,这是不能设置menuView的leftView或者是rightView的,一定要在viewDidLoad或者是reloadData里实现自定义即可!!
WMPageController设置menuView的左右视图
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。