最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實現(xiàn)簡單的二級菜單效果

 更新時間:2016年10月28日 08:55:03   作者:LYSNote  
這篇文章給大家主要介紹的是利用iOS如何實現(xiàn)簡單的菜單效果,文中給出了詳細的示例代碼,而且實現(xiàn)的比較簡單,適合新人學(xué)習(xí)使用。感興趣的朋友們可以參考借鑒,下面來一起看看吧。

首先來看看要實現(xiàn)的效果圖

示例代碼如下

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;
@end
static 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

總結(jié)

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

相關(guān)文章

  • iOS仿微博客戶端一條微博的展示效果

    iOS仿微博客戶端一條微博的展示效果

    這篇文章主要為大家詳細介紹了iOS仿微博客戶端,一條微博的布局,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • iOS實現(xiàn)手勢滑動解鎖功能簡析

    iOS實現(xiàn)手勢滑動解鎖功能簡析

    本篇文章主要介紹了iOS實現(xiàn)手勢滑動解鎖功能簡析,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • iOS中添加文本鏈接和圖片示例代碼

    iOS中添加文本鏈接和圖片示例代碼

    這篇文章主要給大家介紹了關(guān)于iOS中添加文本鏈接和圖片的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-07-07
  • iOS端React Native差異化增量更新的實現(xiàn)方法

    iOS端React Native差異化增量更新的實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于iOS端React Native差異化增量更新的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06
  • Reactnative-iOS回調(diào)Javascript的方法

    Reactnative-iOS回調(diào)Javascript的方法

    這篇文章主要介紹了Reactnative-iOS回調(diào)Javascript的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • iOS輸入框(UITextField)密碼明暗文切換方法

    iOS輸入框(UITextField)密碼明暗文切換方法

    這篇文章主要介紹了iOS輸入框(UITextField)密碼明暗文的切換方法,代碼簡短實用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • iOS 斷點上傳文件的實現(xiàn)方法

    iOS 斷點上傳文件的實現(xiàn)方法

    這項目開發(fā)中,有時候我們需要將本地的文件上傳到服務(wù)器,簡單的幾張圖片還好,但是針對iPhone里面的視頻文件進行上傳,為了用戶體驗,我們有必要實現(xiàn)斷點上傳。這篇文章主要介紹了iOS 斷點上傳文件的實現(xiàn)方法,需要的朋友可以參考下
    2017-12-12
  • iOS設(shè)置圓角的三種方式

    iOS設(shè)置圓角的三種方式

    本文給大家分享ios設(shè)置圓角的三種方式,相對來說最簡單的一種是第一種方法,具體內(nèi)容詳情參考下本文
    2017-03-03
  • ios開發(fā)中時間轉(zhuǎn)換的方法集錦

    ios開發(fā)中時間轉(zhuǎn)換的方法集錦

    這篇文章主要介紹了ios開發(fā)中時間轉(zhuǎn)換的方法集錦,需要的朋友可以參考下
    2015-05-05
  • ios設(shè)計模式--委托模式

    ios設(shè)計模式--委托模式

    這篇文章主要介紹了ios設(shè)計模式中的委托模式,希望對大家學(xué)習(xí)ios框架有所幫助,下面讓我們一起來了解一下吧
    2023-03-03

最新評論

满洲里市| 丹巴县| 义乌市| 诸城市| 钟山县| 西畴县| 和田县| 博湖县| 大新县| 平邑县| 阳城县| 金昌市| 湘阴县| 铜陵市| 塔城市| 安吉县| 东丽区| 施秉县| 建阳市| 民县| 页游| 达州市| 丹凤县| 乐昌市| 隆尧县| 健康| 泰安市| 陵水| 嘉善县| 百色市| 和硕县| 凤山市| 新绛县| 焦作市| 会理县| 丰原市| 育儿| 峡江县| 贺州市| 宜城市| 宝鸡市|