2017最新白帽子教程,持续更新中~~~

iOS常用组件常用使

Uncategorized toy 50℃ 0评论

UICollectionView

最基本用法

1.设置基本布局

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing = 5.0;
    layout.minimumInteritemSpacing = 5.0;
    layout.sectionInset = UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0);
    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; //显示方向设置

2.初始化UICollectionView

UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, topNavCollectionHeight) collectionViewLayout:layout];
collectionView.backgroundColor = [UIColor clearColor];
collectionView.showsHorizontalScrollIndicator = NO;  //隐藏下方滑动条

3.UICollectionView必须设置数据源和代理,如

collectionView.dataSource = self;
    collectionView.delegate = self;

4.cell必须通过注册,如

[collectionView registerClass:[MineCollectionViewCell class] forCellWithReuseIdentifier:collectionCell];
    [collectionView registerClass:[CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionHeader];

5.实现基本代理方法

//分区,组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

//每一分区的单元个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

//集合视图单元格大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

//头部大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section

//集合视图头部或者尾部
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

//单元格复用
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

//被选中的单元格
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

6.others

获取选中cell

TopNavCC *cell = [collectionView cellForItemAtIndexPath:indexPath];

注意点
a.设置scollview的自适应为NO,不然cellForItemAtIndexPath这个方法一直不会被执行

self.automaticallyAdjustsScrollViewInsets = NO;

UILabel

最基本使用

1.初始化UILabel

        _topNavText = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

2.设置相关属性

设置颜色

_topNavText.textColor = themeColor;

设置字体

[_topNavText setFont:[UIFont systemFontOfSize:14]];

设置显示位置(是否居中)

_topNavText.textAlignment = NSTextAlignmentCenter;

UIScollView

1.初始化部分

- (UIScrollView *)mainScollView {
    if (!_mainScollView) {
        _mainScollView = [[UIScrollView alloc]init];
        _mainScollView.delegate = self;
        _mainScollView.bounces = NO;  //滑动边界弹性效果
        _mainScollView.showsHorizontalScrollIndicator = NO;  //水平方向滚动条不显示
        _mainScollView.showsVerticalScrollIndicator = NO;   //垂直方向滚动条不显示
        _mainScollView.pagingEnabled = YES;  //是否翻页
        _mainScollView.contentSize = CGSizeMake(SCREEN_WIDTH * 4, SCREEN_HEIGHT);
    }
    return _mainScollView;
}

动画部分

最基础部分

    [UIView animateWithDuration:1.0f animations:^{
        self.lineView.frame = CGRectMake(indexPath.row * self.LabWidth, self.frame.size.height - lineHeight, self.LabWidth, lineHeight);
    } completion:^(BOOL finished) {
          //动画完成后的处理
    }];

Global部分

基础

变量声明,在本模块(当前.h和.m)有效

static const CGFloat lineHeight = 2;

变量声明,在所有引入头文件中有效

extern const CGFloat lineHeight //在.h文件中
extern const CGFloat lineHeight = 2 //在.m文件中,这个我还没有验证

1.导航设置

转载请注明:链圈一盏灯 » iOS常用组件常用使

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址