iOS 封装 LXHorizontalMenu(仿今日头条、腾讯新闻、网易新闻客户端主页面的第三方)

废话少说,先上gif图

iOS 封装 LXHorizontalMenu(仿今日头条、腾讯新闻、网易新闻客户端主页面的第三方)_第1张图片

下载地址:github.com/NiceForMe/LXHorizontalMenu

一、使用方法

(1)初始化:

LXHorizontalMenu *menu = [[LXHorizontalMenu alloc]initWithFrame:CGRectMake(0, 66, self.view.frame.size.width, self.view.frame.size.height) showSortMenu:YES currentItemArray:self.currentItemsArray restItemArray:self.restItemsArray rootMenuItems:[self rootMenuArray] topMenuHeight:50];

menu.sortButtonImage = [UIImage imageNamed:@"1"];

menu.topMenuBackGoundColor = [UIColor redColor];

menu.delegate = self;

menu.dataSource = self;

menu.itemLabelNormalColor = [UIColor purpleColor];

menu.itemLabelNormalFontSize = 13;

menu.itemLabelSelectColor = [UIColor greenColor];

menu.itemLabelSelectFontSize = 17;

self.automaticallyAdjustsScrollViewInsets = NO;//一定要加上这一行,官方文档的解释为

A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.简单点说就是automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,自动调整scrollview的 inset,设置为no,不让viewController调整,我们自己修改布局即可

[self.view addSubview:menu];

(2)数据源方法

//返回当前有的频道

- (NSInteger)numberOfCurrentItemInHorizontalMenu:(LXHorizontalMenu *)horizontalMenu

{

return self.currentItemsArray.count;

}

//返回所有或者说是剩余的频道

- (NSInteger)numberOfRestItemInHorizontalMenu:(LXHorizontalMenu *)horizontalMenu

{

return self.restItemsArray.count;

}

(3)代理方法

//点击了topmenu的某个button

- (void)horizontalMenu:(LXHorizontalMenu *)horizontalMenu didSelectButtonWithIndex:(NSInteger)index

{

}

//删除了某个button

- (void)horizontalMenu:(LXHorizontalMenu *)horizontalMenu didDeleteButtonWithIndex:(NSInteger)index

{

[self.restItemsArray addObject:self.currentItemsArray[index]];

[self.currentItemsArray removeObjectAtIndex:index];

[self storeArray];

}

//添加了某个button

- (void)horizontalMenu:(LXHorizontalMenu *)horizontalMenu didAddButtonWithIndex:(NSInteger)index

{

ThirdView *tv = [[ThirdView alloc]init];

tv.label.text = self.restItemsArray[index];

[horizontalMenu.rootMenuItems addObject:tv];

[self.currentItemsArray addObject:self.restItemsArray[index]];

[self.restItemsArray removeObjectAtIndex:index];

[self storeArray];

}

//移动了某个button,fromindex为移位的初始值,toindex为移位的终点站

- (void)horizontalMenu:(LXHorizontalMenu *)horizontalMenu didmoveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex

{

//currentItemsArray

id objc = [self.currentItemsArray objectAtIndex:fromIndex];

[self.currentItemsArray removeObject:objc];

[self.currentItemsArray insertObject:objc atIndex:toIndex];

[self storeArray];

}

你可能感兴趣的:(iOS 封装 LXHorizontalMenu(仿今日头条、腾讯新闻、网易新闻客户端主页面的第三方))