
Paste_Image.png
因為今天項目需要用選擇類別的視圖,主要實現的界面就是點擊,下面彈出一個視圖,有兩級列表可選擇??!而且可以上下滑動!用的時候將這個類SkyAssociationMenuView導入項目中,開始上代碼?。?!很簡單,將數組的數據換一下就行了??!
#import "ViewController.h"
#import "SkyAssociationMenuView.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
// 414
#define kScale kScreenWidth/375.0f
#define kkScale kScreenWidth/414.0f
#define khScale kScreenHeight/667.0f
@interface ViewController ()<SkyAssociationMenuViewDelegate>
{
NSArray *titleArr;
NSArray *datArr;
UIButton *btn;
}
@property (strong, nonatomic) SkyAssociationMenuView *tagView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//需要的傳的數組
titleArr = @[@"生活服務",@"職場工作",@"興趣愛好",@"教育學習"];
datArr = @[@[@"交友",@"代購",@"電影",@"跑步",@"美食",@"唱歌",@"逛街",@"游戲",@"旅游",@"陪聊天",@"運動",@"健身",@"養(yǎng)生",@"追星",@"其他愛好"], @[@" IT", @"金融", @"影視", @"傳媒", @"圖書出版", @"設計", @"餐飲", @"零售", @"法律", @"公益",@"求職招聘", @"職場問題", @"其他行業(yè)"],@[@"學前教育", @"中小學教育",@"高等教育",@"家庭教育",@"學習方法", @"留學",@"語言學習", @"音樂舞蹈", @"其他教育"],@[@"租賃",@"跑腿代辦",@"寵物", @"家電維修", @"保潔", @"二手交易",@"醫(yī)療咨詢",@"汽車維修", @"占座排隊",@"母嬰",@"保姆",@"其他服務"]];
_tagView = [[SkyAssociationMenuView alloc] init];
_tagView.delegate = self;
[self show];
}
-(void)show{
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(100, 200, 100, 20);
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"彈框選擇" forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(tan) forControlEvents:UIControlEventTouchUpInside];
}
-(void)tan{
[_tagView showAsFrame:CGRectMake(0, kScreenHeight - 228 * kScale, kScreenWidth, 228 * kScale)];
}
//得到點擊后的文字
-(void)selectFindex:(NSInteger)f Tindex:(NSInteger)t {
NSString *string = datArr[f][t];
[btn setTitle:string forState:UIControlStateNormal];
}
#pragma mark SkyAssociationMenuViewDelegate
- (NSInteger)assciationMenuView:(SkyAssociationMenuView*)asView countForClass:(NSInteger)idx section:(NSInteger)section{
NSLog(@"choose %ld", idx);
if (idx == 0) {
return titleArr.count;
}else if (idx == 1){
NSLog(@"%@",datArr[section]);
return [datArr[section] count];
}
return 0;
}
- (NSString*)assciationMenuView:(SkyAssociationMenuView*)asView titleForClass_1:(NSInteger)idx_1 {
NSLog(@"title %ld", idx_1);
return titleArr[idx_1];
}
- (NSString*)assciationMenuView:(SkyAssociationMenuView*)asView titleForClass_1:(NSInteger)idx_1 class_2:(NSInteger)idx_2 {
return datArr[idx_1][idx_2];
}
- (BOOL)assciationMenuView:(SkyAssociationMenuView*)asView idxChooseInClass1:(NSInteger)idx_1 class2:(NSInteger)idx_2 {
return NO;
}