屌炸天的下拉菜单MKDropdownMenu
效果图:
实现代码:
#define KWidth [UIScreen mainScreen].bounds.size.width
#import "ViewController.h"
#import "UIColor+HCHex.h"
//导入主头文件
#import "MKDropdownMenu.h"
@interface ViewController ()<MKDropdownMenuDataSource,MKDropdownMenuDelegate>
{
NSArray* foodArray;
NSArray* discountsArray;
}
@property (nonatomic, strong)MKDropdownMenu *topDropMenu;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.topDropMenu = [[MKDropdownMenu alloc] initWithFrame:CGRectMake(0, 159, KWidth, 35)];
self.topDropMenu.dataSource = self;
self.topDropMenu.delegate = self;
self.topDropMenu.layer.borderColor = [[UIColor hex_C2C2C2_Color] CGColor];
self.topDropMenu.layer.borderWidth = 0.5;
self.topDropMenu.disclosureIndicatorImage = [UIImage imageNamed:@"voucher_down.png"];
self.topDropMenu.dropdownShowsTopRowSeparator = NO;
self.topDropMenu.dropdownShowsBottomRowSeparator = NO;
self.topDropMenu.dropdownShowsBorder = YES;
self.topDropMenu.backgroundColor = [UIColor clearColor];
self.topDropMenu.componentSeparatorColor = [UIColor hex_929292_Color];
[self.view addSubview:_topDropMenu];
foodArray = @[@"全部美食",@"本帮上海菜",@"日本菜",@"咖啡厅",@"小吃快餐",@"面包甜点",@"火锅",@"西餐",@"自助餐",@"粤菜",@"韩国料理",@"小龙虾",@"轻食",@"东北菜"];
discountsArray = @[@"全部",@"0-30元",@"30-50元",@"50元以上",@"折扣优惠券"];
}
#pragma mark - MKDropdownMenuDataSource
- (NSInteger)numberOfComponentsInDropdownMenu:(MKDropdownMenu *)dropdownMenu {
return 2;
}
- (NSInteger)dropdownMenu:(MKDropdownMenu *)dropdownMenu numberOfRowsInComponent:(NSInteger)component {
switch (component) {
case 0:
return foodArray.count;
case 1:
return discountsArray.count;
default:
return 0;
}
}
#pragma mark - MKDropdownMenuDelegate
- (CGFloat)dropdownMenu:(MKDropdownMenu *)dropdownMenu rowHeightForComponent:(NSInteger)component {
return 35; // default row height
}
- (BOOL)dropdownMenu:(MKDropdownMenu *)dropdownMenu shouldUseFullRowWidthForComponent:(NSInteger)component {
return YES;
}
- (NSAttributedString *)dropdownMenu:(MKDropdownMenu *)dropdownMenu attributedTitleForComponent:(NSInteger)component {
NSString *title;
if (component == 0) {
title = @"美食";
} else {
title = @"优惠";
}
return [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0],NSForegroundColorAttributeName: [UIColor hex_3A3B3C_Color]}];
}
- (NSAttributedString *)dropdownMenu:(MKDropdownMenu *)dropdownMenu attributedTitleForSelectedComponent:(NSInteger)component {
NSString *title;
if (component == 0) {
title = @"美食";
} else {
title = @"优惠";
}
return [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0],NSForegroundColorAttributeName: [UIColor redColor]}];
}
- (NSAttributedString *)dropdownMenu:(MKDropdownMenu *)dropdownMenu attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *rowTitle;
if (component == 0) {
rowTitle = foodArray[row];
} else if (component == 1) {
rowTitle = discountsArray[row];
}
return [[NSAttributedString alloc] initWithString:rowTitle attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10.0],NSForegroundColorAttributeName: [UIColor hex_3A3B3C_Color]}];
}
- (UIColor *)dropdownMenu:(MKDropdownMenu *)dropdownMenu backgroundColorForRow:(NSInteger)row forComponent:(NSInteger)component {
return [UIColor clearColor];
}
- (void)dropdownMenu:(MKDropdownMenu *)dropdownMenu didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
[dropdownMenu closeAllComponentsAnimated:YES];
NSLog(@"选择了第 %ld 列的第 %ld 行",(long)component,(long)row);
}
@end
相关推荐
- 《庆余年》监察院门前的碑文初看是不是屌炸天?看过原著中原文后你才会知道什么是真厉害!...
- 百度的71个炸天的开源项目
- 骆驼男鞋怎么样,骆驼男鞋售后逆天,骆驼男鞋维修36天无结果。程序员屌丝的维权之路,直播。。。。。。...
- 屌炸了!阿里巴巴P7+大牛编写的Spring Boot+Spring Cloud微服务开发实战笔记,受益匪浅!
- 搜索功能吊炸天,出门在外通过Outlook手机APP快速找到那个骚气的技术宅
- 用了2年6个月11天,从屌丝外包到阿里的逆袭之路
- 【原理分析】Google"炫炸天"的平衡自行车仅仅是概念吗?来看看惯性轮自行车吧...
- 炸了!这家交易所的逆天模式,让赵长鹏完全绷不住了
- 春节红包怎么花,花出酷炫吊炸天的感觉~
- 屌炸天的下拉菜单MKDropdownMenu
- DCN的Cross操作的优缺点
- 重大消息:华为笔记本电脑开始用LINUX系统