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

iOS開(kāi)發(fā)仿電商類APP首頁(yè)實(shí)例

 更新時(shí)間:2016年11月07日 11:17:37   作者:zhifenx  
本篇文章主要介紹了iOS開(kāi)發(fā)仿電商類APP首頁(yè)實(shí)例,主要是利用ui布局,具有一定的參考價(jià)值,有需要的可以了解一下。

現(xiàn)在淘寶,京東應(yīng)用很廣泛,今天就效仿做一個(gè)類似電商APP首頁(yè)的實(shí)例。

一、Gif效果圖:

二、UI布局:
看下圖的層級(jí)關(guān)系,除去最下方的TabBar,首頁(yè)其余部分全是用UICollectionView實(shí)現(xiàn);其分兩大部分,實(shí)現(xiàn)三種功能。上方是父UICollectionView的headerView,在此headerView中添加了兩個(gè)UICollectionView,分別實(shí)現(xiàn)圖片無(wú)限輪播器和一個(gè)橫向滑動(dòng)的功能菜單按鈕。然后下面就是父UICollectionView的cell,上下滑動(dòng)展示商品內(nèi)容。

三、代碼:

因?yàn)檫@篇文章主要是講如何實(shí)現(xiàn)電商類APP首頁(yè)布局的,所以如何設(shè)置UICollectionView我就不再贅述,網(wǎng)上有很多這方面的章。

下面是主控制器MYIHomeViewController.m文件中的代碼,初始化父UICollectionView的代碼就在這里面,貼出這部分代碼是有些地方需要特別注意,有需要的可以下載源碼:https://pan.baidu.com/s/1dFsnJpR

#import "MYIHomeViewController.h"

#import "MYIHomeHeaderView.h"
#import "JFConfigFile.h"
#import "MYIHomeLayout.h"
#import "MYIHomeCell.h"

static NSString *ID = @"collectionViewCell";

@interface MYIHomeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation MYIHomeViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  //關(guān)閉自動(dòng)調(diào)整滾動(dòng)視圖(不關(guān)閉圖片輪播器會(huì)出現(xiàn)問(wèn)題)
  self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];

  //隱藏navigationBar
  self.navigationController.navigationBar.hidden = YES;
}

- (void)loadView {
  [super loadView];

  //添加collectionView
  [self.view addSubview:self.collectionView];
}

//懶加載collectionView
- (UICollectionView *)collectionView {
  if (!_collectionView) {
    _collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:[[MYIHomeLayout alloc] init]];
    _collectionView.backgroundColor = JFRGBColor(238, 238, 238);

    //注冊(cè)cell
    [_collectionView registerClass:[MYIHomeCell class] forCellWithReuseIdentifier:ID];

    //注冊(cè)UICollectionReusableView即headerView(切記要添加headerView一定要先注冊(cè))
    [_collectionView registerClass:[MYIHomeHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];

    _collectionView.delegate = self;
    _collectionView.dataSource = self;
  }
  return _collectionView;
}

#pragma mark ---UICollectionViewDataSource 數(shù)據(jù)源方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  return 80;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  MYIHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  cell.iconName = @"goodsimagetest";
  cell.describe = @"螞蟻到家螞蟻到家螞蟻到家";
  cell.currentPrice = @"¥100";
  cell.originalPrice = @"¥288";
  return cell;
}

//添加headerView
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  MYIHomeHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];;

  //判斷上面注冊(cè)的UICollectionReusableView類型
  if (kind == UICollectionElementKindSectionHeader) {
    return headerView;
  }else {
    return nil;
  }
}

#pragma mark ---UICollectionViewDelegate
//設(shè)置headerView的寬高
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {

  return CGSizeMake(self.view.bounds.size.width, 380);
}

#pragma mark ---UICollectionViewDelegateFlowLayout

//設(shè)置collectionView的cell上、左、下、右的間距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  return UIEdgeInsetsMake(14, 0, 0, 0);
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

@end

注意:

1、在主控制器中最好將automaticallyAdjustsScrollViewInsets屬性設(shè)置為NO這個(gè)原因我在上一篇文章一行代碼實(shí)現(xiàn)圖片無(wú)限輪播器中有說(shuō)明,如果在有NavigationBar的情況下如果不設(shè)置就會(huì)自動(dòng)調(diào)整滾動(dòng)視圖的frame,這樣會(huì)導(dǎo)致輪播器imageView顯示錯(cuò)位。

- (void)viewDidLoad {
   [super viewDidLoad]; 

  //關(guān)閉自動(dòng)調(diào)整滾動(dòng)視圖(不關(guān)閉圖片輪播器會(huì)出現(xiàn)問(wèn)題)
   self.automaticallyAdjustsScrollViewInsets = NO;
}

2、UICollectionView的UICollectionReusableView就相當(dāng)于UITableView的headerView和footerView,要想給UICollectionView追加headerView就必須先注冊(cè),且追加的類型是UICollectionElementKindSectionHeader相對(duì)應(yīng)的UICollectionElementKindSectionFooter就是追加footerView

實(shí)例化UICollectionView時(shí)的注冊(cè)UICollectionReusableView代碼

//注冊(cè)UICollectionReusableView即headerView(切記要添加headerView一定要先注冊(cè))
    [_collectionView registerClass:[MYIHomeHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];

3、實(shí)現(xiàn)UICollectionView的數(shù)據(jù)源代理方法- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

//添加headerView
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  MYIHomeHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];

  //判斷上面注冊(cè)的UICollectionReusableView類型
  if (kind == UICollectionElementKindSectionHeader) {
    return headerView;
  }else {
    return nil;
  }
}

下面是項(xiàng)目文件夾說(shuō)明:

下載完成解壓后請(qǐng)打開(kāi)這個(gè)文件運(yùn)行項(xiàng)目:

四、總結(jié):

1、實(shí)現(xiàn)這種首頁(yè)布局其實(shí)還可以用UITableView,原理差不多就看功能需求,這里就簡(jiǎn)單的實(shí)現(xiàn)了此類電商APP的首頁(yè),像淘寶和京東那樣更復(fù)雜的UI布局,有興趣的同學(xué)可以研究一下,希望這篇文章可以給你帶來(lái)收獲和啟發(fā),歡迎評(píng)論交流。

最后:源碼下載

相關(guān)文章

  • iOS UIAlertController中UITextField添加晃動(dòng)效果與邊框顏色詳解

    iOS UIAlertController中UITextField添加晃動(dòng)效果與邊框顏色詳解

    這篇文章主要給大家介紹了關(guān)于iOS UIAlertController中UITextField添加晃動(dòng)效果與邊框顏色的相關(guān)資料,實(shí)現(xiàn)后的效果非常適合在開(kāi)發(fā)中使用,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒,下面隨著小編來(lái)一起看看吧。
    2017-10-10
  • iOS masonry的使用方法

    iOS masonry的使用方法

    這篇文章主要介紹了iOS masonry的基本使用方法的相關(guān)資料,文章還介紹了CocoaPods的安裝過(guò)程,需要的朋友可以參考下面文字內(nèi)容
    2021-09-09
  • iOS設(shè)計(jì)模式——Category簡(jiǎn)單介紹

    iOS設(shè)計(jì)模式——Category簡(jiǎn)單介紹

    這篇文章主要介紹了iOS設(shè)計(jì)模式——Category簡(jiǎn)單介紹,有興趣學(xué)習(xí)的同學(xué)可以了解一下。
    2016-11-11
  • iOS?組件化初步構(gòu)思

    iOS?組件化初步構(gòu)思

    這篇文章主要介紹了iOS組件化初步構(gòu)思,并對(duì)iOS組件化常用方式的討論進(jìn)行了方案分析,以便幫助大家對(duì)ios組件化有一個(gè)深刻的了解
    2023-03-03
  • iOS中延時(shí)執(zhí)行的幾種方式比較及匯總

    iOS中延時(shí)執(zhí)行的幾種方式比較及匯總

    這篇文章主要給大家介紹了關(guān)于iOS中延時(shí)執(zhí)行的幾種方式比較及匯總,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-02-02
  • IOS與網(wǎng)頁(yè)JS交互詳解及實(shí)例

    IOS與網(wǎng)頁(yè)JS交互詳解及實(shí)例

    這篇文章主要介紹了 IOS與網(wǎng)頁(yè)JS交互詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • iOS指紋登錄(TouchID)集成方案詳解

    iOS指紋登錄(TouchID)集成方案詳解

    這篇文章主要為大家詳細(xì)介紹了iOS指紋登錄TouchID的集成方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • iOS中的表單按鈕選項(xiàng)UIActionSheet常用方法整理

    iOS中的表單按鈕選項(xiàng)UIActionSheet常用方法整理

    UIActionSheet經(jīng)常被用來(lái)制作各種彈出的選項(xiàng),這里我們就來(lái)看一下iOS中的表單按鈕選項(xiàng)UIActionSheet常用方法整理,需要的朋友可以參考下
    2016-06-06
  • IOS CocoaPods詳解之進(jìn)階篇

    IOS CocoaPods詳解之進(jìn)階篇

    這篇文章主要介紹了IOS CocoaPods詳解之進(jìn)階篇,需要的朋友可以參考下
    2016-09-09
  • 學(xué)習(xí)iOS開(kāi)關(guān)按鈕UISwitch控件

    學(xué)習(xí)iOS開(kāi)關(guān)按鈕UISwitch控件

    這篇文章主要為大家詳細(xì)介紹了iOS開(kāi)關(guān)按鈕UISwitch控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-08-08

最新評(píng)論

阿克苏市| 鄯善县| 邹平县| 伊春市| 仁怀市| 曲松县| 德化县| 日土县| 通海县| 五大连池市| 仲巴县| 兴国县| 普安县| 鹿邑县| 禹城市| 分宜县| 花垣县| 宜兰县| 五大连池市| 城市| 靖远县| 师宗县| 莱州市| 广西| 江孜县| 双江| 安塞县| 南涧| 平阴县| 尼勒克县| 丰都县| 桂阳县| 蓬莱市| 台东市| 怀来县| 星座| 红河县| 洪洞县| 依兰县| 磐石市| 朝阳县|