亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > iOS > 正文

iOS實現簡單的二級菜單效果

2020-07-26 03:07:35
字體:
來源:轉載
供稿:網友

首先來看看要實現的效果圖

示例代碼如下

Untitled.gif#import "ViewController.h"#import "CollectionViewCell.h"#import "CollectionSectionView.h"@interface ViewController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>@property (nonatomic,strong)UICollectionView *collectionView;@property (nonatomic,copy)NSString *leftOrRight;@property (nonatomic,strong)NSIndexPath *clickIndexPath;@endstatic NSString *cellIdentifier = @"CollectionViewCell";static NSString *sectionIdentifier = @"CollectionSectionView";@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.itemSize = CGSizeMake(50, 25); flowLayout.minimumLineSpacing = 0; flowLayout.minimumInteritemSpacing = 0; flowLayout.headerReferenceSize = CGSizeMake(0, 40); flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout]; _collectionView.backgroundColor = [UIColor whiteColor]; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier]; [_collectionView registerClass:[CollectionSectionView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:sectionIdentifier]; [self.view addSubview:_collectionView];}- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 3;}- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (self.clickIndexPath.section == section) {  if (self.clickIndexPath.section == 0 && [self.leftOrRight isEqualToString:@"left"]) {   return 3;  }  if (self.clickIndexPath.section == 0 && [self.leftOrRight isEqualToString:@"right"]) {   return 4;  }  if (self.clickIndexPath.section == 1 && [self.leftOrRight isEqualToString:@"left"]) {   return 10;  }  if (self.clickIndexPath.section == 1 && [self.leftOrRight isEqualToString:@"right"]) {   return 8;  }  if (self.clickIndexPath.section == 2 && [self.leftOrRight isEqualToString:@"left"]) {   return 33;  }  if (self.clickIndexPath.section == 2 && [self.leftOrRight isEqualToString:@"right"]) {   return 6;  } } return 0;}- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; cell.label.text = [NSString stringWithFormat:@"%ld-%ld",indexPath.section,indexPath.row]; return cell;}- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {  CollectionSectionView *sectionView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:sectionIdentifier forIndexPath:indexPath];  sectionView.backgroundColor = [UIColor lightGrayColor];  sectionView.leftStr = @"家具";  sectionView.rightStr = @"家電";  [sectionView customBtnHandelAction:^(NSString *leftOrRight) {   self.clickIndexPath = indexPath;   self.leftOrRight = leftOrRight;   [collectionView reloadData];  }];  return sectionView; } return nil;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
#import <UIKit/UIKit.h>typedef void(^BtnHandleAction)(NSString *leftOrRight);@interface CollectionSectionView : UICollectionReusableView@property (nonatomic,copy)NSString *leftStr;@property (nonatomic,copy)NSString *rightStr;- (void)customBtnHandelAction:(BtnHandleAction)action;@end
#import "CollectionSectionView.h"@interface CollectionSectionView ()@property (nonatomic,strong)UIButton *leftBtn;@property (nonatomic,strong)UIButton *rightBtn;@property (nonatomic,copy)BtnHandleAction btnHandelAction;@end@implementation CollectionSectionView- (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) {  [self setup]; } return self;}- (UIButton *)leftBtn{ if (!_leftBtn) {  self.leftBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];  _leftBtn.tag = 2000;  _leftBtn.frame = CGRectMake(1, 1, self.frame.size.width / 2 - 2, self.frame.size.height - 2);  _leftBtn.backgroundColor = [UIColor whiteColor];  [_leftBtn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)]; } return _leftBtn;}- (UIButton *)rightBtn{ if (!_rightBtn) {  self.rightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];  _rightBtn.tag = 2001;  _rightBtn.frame = CGRectMake(self.frame.size.width / 2 + 1, 1, self.frame.size.width / 2 - 2, self.frame.size.height - 2);  _rightBtn.backgroundColor = [UIColor whiteColor];  [_rightBtn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)]; } return _rightBtn;}- (void)btnAction:(UIButton *)sender{ NSInteger tag = sender.tag; if (tag == 2000) {  self.btnHandelAction(@"left"); } if (tag == 2001) {  self.btnHandelAction(@"right"); }}- (void)customBtnHandelAction:(BtnHandleAction)action{ self.btnHandelAction = action;}- (void)setup{ [self addSubview:self.leftBtn]; [self addSubview:self.rightBtn];}- (void)setLeftStr:(NSString *)leftStr{ [self.leftBtn setTitle:leftStr forState:(UIControlStateNormal)]; [self.leftBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];}- (void)setRightStr:(NSString *)rightStr{ [self.rightBtn setTitle:rightStr forState:(UIControlStateNormal)]; [self.rightBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];}@end

總結

以上就是這篇文章的全部內容,希望本文的內容對大家的學習或者工作能有所幫助,如果有疑問大家可以留言交流。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
在线观看视频亚洲| 久久久91精品国产一区不卡| 91国在线精品国内播放| 欧美影院成年免费版| 亚洲一区二区三区成人在线视频精品| 欧美成人一区二区三区电影| 北条麻妃99精品青青久久| 亚洲精品一区av在线播放| 久久久欧美一区二区| 欧美午夜xxx| 国产精品色午夜在线观看| 亚洲最大成人网色| 在线观看国产成人av片| 亚洲护士老师的毛茸茸最新章节| 久久天天躁狠狠躁老女人| 欧美与欧洲交xxxx免费观看| 国产一区二区丝袜| 狠狠躁夜夜躁人人爽天天天天97| 久久久av网站| 精品中文视频在线| 日本国产高清不卡| 欧美理论片在线观看| 国产精品一区二区久久| 亚洲毛片在线观看| 国语自产精品视频在线看抢先版图片| 国产日韩在线精品av| 欧美电影在线观看| 欧美成人午夜视频| 青草热久免费精品视频| 色99之美女主播在线视频| 国产精品久久久av| 日韩专区在线观看| 午夜精品国产精品大乳美女| 国产丝袜一区二区| 欧美成人精品xxx| 精品香蕉一区二区三区| 欧美日韩国产黄| 久久91亚洲精品中文字幕奶水| 日韩免费在线观看视频| 亚洲精品自产拍| 亚洲欧美激情四射在线日| 色噜噜久久综合伊人一本| 国产精品福利无圣光在线一区| 亚洲欧美视频在线| 久久久视频免费观看| 国产精品亚发布| 精品久久久久久久久久久久| 亚洲精品电影网站| 欧美激情在线播放| 亚洲第一视频网站| 亚洲女人天堂色在线7777| 亚洲丁香久久久| 日韩在线观看成人| 国产亚洲精品久久久久久777| 国产精自产拍久久久久久| 国产99久久精品一区二区| 国产成人亚洲综合青青| 97视频在线观看免费高清完整版在线观看| 欧美另类极品videosbest最新版本| 成人在线视频网站| 97久久精品国产| 成人黄色片网站| 中文字幕不卡在线视频极品| 欧美激情国产日韩精品一区18| 亚洲xxx视频| 欧美专区福利在线| 中文字幕亚洲无线码在线一区| 日韩欧美中文字幕在线播放| 第一福利永久视频精品| 精品美女国产在线| 97精品在线视频| 亚洲第一级黄色片| 日本19禁啪啪免费观看www| 日本国产精品视频| 亚洲精品电影网在线观看| 亚洲综合一区二区不卡| 欧美激情一区二区三级高清视频| 国内外成人免费激情在线视频网站| 亚洲永久在线观看| 成年人精品视频| 久久综合电影一区| 亚洲理论在线a中文字幕| 国产精品午夜国产小视频| 欧洲亚洲妇女av| 伦伦影院午夜日韩欧美限制| 亚洲丝袜一区在线| 精品久久久久久久久久| 久久影视三级福利片| 成人免费看黄网站| 日韩av在线不卡| 成人在线播放av| 日韩av在线高清| 91欧美精品成人综合在线观看| 亚洲女人天堂成人av在线| 国产一区玩具在线观看| 国产成人一区二区三区| 国产免费久久av| 在线观看亚洲区| 欧美日韩免费在线| 亚洲xxxx视频| 亚洲最大av网| 欧美片一区二区三区| 国产精品国产自产拍高清av水多| 国产欧美一区二区三区久久| 热久久免费国产视频| 中文字幕v亚洲ⅴv天堂| 亚洲sss综合天堂久久| 亚洲免费精彩视频| 色偷偷偷综合中文字幕;dd| 91精品在线观看视频| 国内精品久久久久久影视8| 欧美性视频网站| 在线播放国产精品| 黄色一区二区在线| 日韩国产高清污视频在线观看| 欧美色视频日本高清在线观看| 疯狂欧美牲乱大交777| 热99精品只有里视频精品| 日韩免费在线观看视频| 日韩精品在线播放| 亚洲欧美精品一区| 国内精品久久久久影院优| 国产精品一二区| 欧美日韩一区二区免费在线观看| 午夜精品久久久久久久久久久久| 国产成人自拍视频在线观看| 欧美高清理论片| 欧美日韩中文字幕综合视频| 亚洲欧美制服另类日韩| 亚洲成人av资源网| 韩曰欧美视频免费观看| 国产精品综合久久久| 色哟哟亚洲精品一区二区| 欧美精品videosex牲欧美| 精品国产1区2区| 亚洲精品电影网站| 成人在线免费观看视视频| 91精品国产综合久久香蕉| 中文字幕亚洲欧美日韩2019| 精品国产老师黑色丝袜高跟鞋| 久久久亚洲精选| 欧美在线观看一区二区三区| 欧美日韩国产二区| 日韩av在线网站| 成人伊人精品色xxxx视频| 亚洲欧美国产精品久久久久久久| 欧美一区二区三区四区在线| 欧美夫妻性生活视频| 亚洲国产精品久久91精品| 日韩成人av在线播放| 97在线看福利| 91九色精品视频| 最近2019中文免费高清视频观看www99| 亚洲欧美三级伦理| 51色欧美片视频在线观看| 国产精品嫩草影院一区二区| 亚洲国产婷婷香蕉久久久久久| 热草久综合在线| 亚洲国产精品热久久| 成人性生交大片免费看视频直播| 91精品久久久久久久久久入口| 欧美孕妇与黑人孕交| 国产精品九九久久久久久久| 国产一区二区三区三区在线观看|