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

iOS UICollectionView實(shí)現(xiàn)橫向滑動(dòng)

 更新時(shí)間:2020年03月24日 11:23:37   作者:開發(fā)仔XG  
這篇文章主要為大家詳細(xì)介紹了iOS UICollectionView實(shí)現(xiàn)橫向滑動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS UICollectionView實(shí)現(xiàn)橫向滑動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

UICollectionView的橫向滾動(dòng),目前我使用在了顯示輸入框的輸入歷史上;

//
// SCVisitorInputAccessoryView.m
// 訪客通行錄入頁面--訪客姓名輸入歷史的InputAccessory

#import "SCInputAccessoryView.h"
#import "SCInputAccessoryCell.h"

#define SCHorizontalMargin 15.0f
#define SCVerticalMargin 10.0f

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

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

/// 名字記錄的數(shù)組
@property (nonatomic, strong) NSMutableArray *nameArray;

@end


@implementation SCInputAccessoryView

+ (instancetype)loadNibView {
 return [[[NSBundle mainBundle] loadNibNamed:[SCInputAccessoryView className] owner:self options:nil] objectAtIndex:0];
}

- (void)awakeFromNib {
 [super awakeFromNib];
 self.clipsToBounds = YES;
 self.collectionView.delegate = self;
 self.collectionView.dataSource = self;
 [self setupView];
}

- (void)setupView {

 /// 設(shè)置此屬性為yes 不滿一屏幕 也能滾動(dòng)
 self.collectionView.alwaysBounceHorizontal = YES;
 self.collectionView.showsHorizontalScrollIndicator = NO;
 // 1.創(chuàng)建流水布局
 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
 layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
 self.collectionView.collectionViewLayout = layout;
 [self registerNibWithTableView];
}

#pragma mark - 代理方法 Delegate Methods
// 設(shè)置分區(qū)

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
 return 1;
}

// 每個(gè)分區(qū)上得元素個(gè)數(shù)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
 return self.nameArray.count;
}

// 設(shè)置cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

 SCInputAccessoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SCInputAccessoryCell class]) forIndexPath:indexPath];
 [cell refreshCellWithTitle:self.nameArray[indexPath.row]];
 return cell;
}

// 設(shè)置cell大小 itemSize:可以給每一個(gè)cell指定不同的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
 CGFloat height = 35.0f;
 CGFloat width = [self gainStringWidthWithString:self.nameArray[indexPath.row] font:15.0f height:height];
 return CGSizeMake(width, height);
}


// 設(shè)置UIcollectionView整體的內(nèi)邊距(這樣item不貼邊顯示)
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
 // 上 左 下 右
 return UIEdgeInsetsMake(SCVerticalMargin, SCHorizontalMargin, SCVerticalMargin, SCHorizontalMargin);
}

// 設(shè)置minimumLineSpacing:cell上下之間最小的距離
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
 return SCHorizontalMargin;
}

// 設(shè)置minimumInteritemSpacing:cell左右之間最小的距離
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
 return SCHorizontalMargin;
}

// 選中cell的回調(diào)
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 if (self.selectRowBlock) {
 self.selectRowBlock(indexPath.row, self.nameArray[indexPath.row]);
 }
}

#pragma mark - 對外方法 Public Methods
/// array數(shù)組里面放的元素 必須字符串類型的
- (void)refreshUIWithNameArray:(NSArray<NSString *> *)array {
 [self.nameArray removeAllObjects];
 [self.nameArray addObjectsFromArray:array];
 [self.collectionView reloadData];
}


#pragma mark - 內(nèi)部方法 Private Methods
// 注冊cell
- (void)registerNibWithTableView {
 [self.collectionView registerNib:[UINib nibWithNibName:[SCInputAccessoryCell className] bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([SCInputAccessoryCell class])];
}

- (CGFloat)gainStringWidthWithString:(NSString *)string font:(CGFloat)font height:(CGFloat)height {

 if (string.length == 0) {
 return 0.0f;
 }

 CGSize maxSize = CGSizeMake(MAXFLOAT, height);
 CGSize realSize = [string boundingRectWithSize:maxSize
   options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
   attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}
   context:nil].size;
 /// 左右各16
 return (realSize.width + 2 * (SCHorizontalMargin + 1.f));
}

#pragma mark - 點(diǎn)擊/觸碰事件 Action Methods

#pragma mark - 懶加載 Lazy Load

- (NSMutableArray *)nameArray {
 if (!_nameArray) {
 _nameArray = [NSMutableArray arrayWithCapacity:0];
 }
 return _nameArray;
}

@end

效果圖:

Demo地址 :XGDevelopDemo

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS 簡單的操作桿旋轉(zhuǎn)實(shí)現(xiàn)示例詳解

    iOS 簡單的操作桿旋轉(zhuǎn)實(shí)現(xiàn)示例詳解

    這篇文章主要為大家介紹了iOS 簡單的操作桿旋轉(zhuǎn)實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Swift 開發(fā)之懶加載的實(shí)例詳解

    Swift 開發(fā)之懶加載的實(shí)例詳解

    這篇文章主要介紹了Swift 開發(fā)之懶加載的實(shí)例詳解的相關(guān)資料,希望通過本文能幫助到大家,實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-09-09
  • iOS開發(fā)之觸摸事件

    iOS開發(fā)之觸摸事件

    iOS設(shè)備都是可以多點(diǎn)觸摸的,是指手指放在iOS設(shè)備的屏幕上從屏幕上拖動(dòng)或抬起。系統(tǒng)當(dāng)前視圖響應(yīng)觸摸事件,若無響應(yīng)則向上層傳遞,構(gòu)成響應(yīng)者鏈。觸摸事件的函數(shù)有4個(gè)。
    2016-04-04
  • 詳解iOS平臺調(diào)用后臺接口的正確姿勢

    詳解iOS平臺調(diào)用后臺接口的正確姿勢

    這篇文章主要介紹了詳解iOS平臺調(diào)用后臺接口的正確姿勢,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • 詳解iOS社會(huì)化分享集成

    詳解iOS社會(huì)化分享集成

    這篇文章主要介紹了詳解iOS社會(huì)化分享集成的相關(guān)知識點(diǎn)以及實(shí)現(xiàn)的代碼效果講述,有興趣的朋友參考下。
    2018-02-02
  • iOS中多線程的入門使用教程(Swift)

    iOS中多線程的入門使用教程(Swift)

    這篇文章主要給大家介紹了關(guān)于iOS中多線程入門使用的相關(guān)資料,一個(gè)進(jìn)程中可以開啟多條線程,每條線程可以并行執(zhí)行不同的任務(wù),本文通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-11-11
  • iOS通過shell腳本批量修改屬性

    iOS通過shell腳本批量修改屬性

    這篇文章主要給大家分享了iOS通過shell腳本批量修改屬性的相關(guān)知識點(diǎn),希望我們整理的內(nèi)容能夠幫助到大家。
    2018-03-03
  • iOS如何獲取當(dāng)前View所在控制器的方法

    iOS如何獲取當(dāng)前View所在控制器的方法

    在開發(fā)iOS的時(shí)候經(jīng)常需要獲取當(dāng)前View所在的控制器,下面小編給大家分享個(gè)方法,文章給出了示例代碼,對大家的學(xué)習(xí)和理解很有幫助,下面來一起看看吧。
    2016-09-09
  • iOS獲取手機(jī)通訊錄方式方法(最新)

    iOS獲取手機(jī)通訊錄方式方法(最新)

    本篇文章主要介紹了iOS獲取手機(jī)通訊錄方式方法(最新),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • iOS13適配三指撤銷和文案限長實(shí)例詳解

    iOS13適配三指撤銷和文案限長實(shí)例詳解

    這篇文章主要為大家介紹了iOS13適配三指撤銷和文案限長實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01

最新評論

西丰县| 鞍山市| 张家川| 达拉特旗| 祁门县| 广州市| 安仁县| 原阳县| 临澧县| 宜宾市| 乐至县| 潞西市| 武乡县| 黄平县| 小金县| 湖北省| 望奎县| 虎林市| 盖州市| 富源县| 渝北区| 鱼台县| 黎川县| 都安| 建水县| 望都县| 册亨县| 应城市| 商南县| 沁阳市| 青冈县| 云浮市| 玛纳斯县| 濮阳市| 安塞县| 青岛市| 碌曲县| 彩票| 鞍山市| 尤溪县| 拉孜县|