scrollView切换

需求:类似导航栏上有三个不同类型的账单类型(未还清、已结清、其他),要求即可点击某一类型切换到所点击类型,也可手势左右滑动切换到想要切换的类型,类型下线条跟着切换的类型滑动。 放张效果图:

PS:顺便把tableViewCell的四种类型效果也做了下。

继续放图:

Demo结构:

git图:

代码(后面有时间会将代码传到github把链接贴出来): 约束用的PureLayout。

  • AppDelegate.m代码:
//
//  AppDelegate.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    ViewController *vc = [[ViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    
    self.window.rootViewController = nav;
    
    [self.window makeKeyAndVisible];
    
    return YES;
}
复制代码
  • ViewController:
//
//  ViewController.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "ViewController.h"
#import "CaiFirstTableView.h"
#import "CaiSecondTableView.h"
#import "CaiThirdTableView.h"
#import "PureLayout.h"
#import "CaiCommon.h"
#import "CaiPushViewController.h"

#define AnimationInterval 0.15

@interface ViewController ()<UIScrollViewDelegate, CaiPushDelegate>

@property (nonatomic, strong) UIView *titleView;//头部视图View
@property (nonatomic, strong) NSArray *titleArray;//头部视图title
@property (nonatomic, strong) UIScrollView *contentScrollView;//内容滑动视图-左右
@property (nonatomic, assign) NSInteger index;//偏移--0:first  1:second  2:third
@property (nonatomic, strong) CaiFirstTableView *firstTableView;
@property (nonatomic, strong) CaiSecondTableView *secondTableView;
@property (nonatomic, strong) CaiThirdTableView *thirdTableView;

@property (nonatomic, strong) UIButton *firstBtn;
@property (nonatomic, strong) UIButton *secondBtn;
@property (nonatomic, strong) UIButton *thirdBtn;

@property (nonatomic, strong) UIView *underLineView;

@end

@implementation ViewController

#pragma mark -lazy load
- (UIView *)titleView
{
    if (!_titleView) {
        _titleView = [UIView newAutoLayoutView];
        _titleView.backgroundColor = [UIColor cyanColor];
    }
    return _titleView;
}

- (UIScrollView *)contentScrollView
{
    if (!_contentScrollView) {
        _contentScrollView = [UIScrollView newAutoLayoutView];
        _contentScrollView.backgroundColor = [UIColor grayColor];
        _contentScrollView.delegate = self;
        _contentScrollView.pagingEnabled = YES;
        _contentScrollView.bounces = NO;
        _contentScrollView.showsHorizontalScrollIndicator = NO;
        _contentScrollView.showsVerticalScrollIndicator = NO;
    }
    return _contentScrollView;
}

- (UIView *)underLineView
{
    if (!_underLineView) {
        if (_index == 1) {
            _underLineView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_Width/3.0, 47, SCREEN_Width/3.0, 2)];
        }else if (_index == 2) {
            _underLineView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_Width/3.0 * 2, 47, SCREEN_Width/3.0, 2)];
        }else {
            _underLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 47, SCREEN_Width/3.0, 2)];
        }
        
        _underLineView.backgroundColor = [UIColor blueColor];
    }
    return _underLineView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"test";
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    _index = 0;//首次进入默认第一个视图
    _titleArray = @[@"first", @"second", @"third"];
    
    [self createTitleView];
    [self createContentView];
    [self addTitleButton];
    [self addTableViews];
}

- (void)addTableViews
{
    for (int i = 0; i < 3; i ++) {
        
        if ( i == 0) {//未还清
            //  64:状态栏高度 + 导航栏高度  49:titleView高度
            self.firstTableView = [[CaiFirstTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_Width, SCREEN_Height - 64 -  49) style:UITableViewStylePlain];
            self.firstTableView.pushDelegate = self;
            [self.contentScrollView addSubview:self.firstTableView];
        }
        
        if ( i == 1) {//已还清
            self.secondTableView = [[CaiSecondTableView alloc] initWithFrame:CGRectMake(SCREEN_Width, 0, SCREEN_Width, SCREEN_Height - 64 - 49) style:UITableViewStylePlain];
            [self.contentScrollView addSubview:self.secondTableView];
        }
        
        if (i == 2) {//其他
            self.thirdTableView = [[CaiThirdTableView alloc] initWithFrame:CGRectMake(2 * SCREEN_Width, 0, SCREEN_Width, SCREEN_Height - 64 - 49) style:UITableViewStylePlain];
            [self.contentScrollView addSubview:self.thirdTableView];
        }
    }
}

#pragma mark -titleView
- (void)createTitleView
{
#pragma mark -头部view
    [self.view addSubview:self.titleView];
    
    [self.titleView autoSetDimensionsToSize:CGSizeMake(SCREEN_Width, 49)];
    [self.titleView autoPinEdgeToSuperviewEdge:ALEdgeTop];
}

#pragma mark -contentView
- (void)createContentView
{
#pragma mark -内容视图
    [self.view addSubview:self.contentScrollView];
    
    [_contentScrollView autoPinEdgeToSuperviewEdge:ALEdgeLeading];
    [_contentScrollView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
    [_contentScrollView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_titleView];
    [_contentScrollView autoSetDimension:ALDimensionHeight toSize:SCREEN_Height - 64 - 47 - 2];
    
    self.contentScrollView.contentSize = CGSizeMake(SCREEN_Width * _titleArray.count, 0);
    [self.contentScrollView setContentOffset:CGPointMake(_index * SCREEN_Width, 0)];
}

#pragma mark -addBtn
- (void)addTitleButton
{
    [self.titleView addSubview:self.underLineView];
    
    _firstBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _firstBtn.titleLabel.font = FONT(15);
    [_firstBtn setTitle:_titleArray[0] forState:UIControlStateNormal];
    [_firstBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [_firstBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self.titleView addSubview:self.firstBtn];
    if (self.index == 0) {
        self.firstBtn.selected = YES;
    }else {
        self.firstBtn.selected = NO;
    }
    
    [_firstBtn addTarget:self action:@selector(firstBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    _secondBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _secondBtn.titleLabel.font = FONT(15);
    [_secondBtn setTitle:_titleArray[1] forState:UIControlStateNormal];
    [_secondBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [_secondBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self.titleView addSubview:self.secondBtn];
    if (self.index == 1) {
        self.secondBtn.selected = YES;
    }else {
        self.secondBtn.selected = NO;
    }
    [_secondBtn addTarget:self action:@selector(secondBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    _thirdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _thirdBtn.titleLabel.font = FONT(15);
    [_thirdBtn setTitle:_titleArray[2] forState:UIControlStateNormal];
    [_thirdBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [_thirdBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self.titleView addSubview:self.thirdBtn];
    if (self.index == 2) {
        self.thirdBtn.selected = YES;
    }else {
        self.thirdBtn.selected = NO;
    }
    [_thirdBtn addTarget:self action:@selector(thirdBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    [_firstBtn autoPinEdgeToSuperviewEdge:ALEdgeLeading];
    [_firstBtn autoSetDimension:ALDimensionWidth toSize:(SCREEN_Width/3.0)];
    [_firstBtn autoSetDimension:ALDimensionHeight toSize:49];
    [_firstBtn autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_titleView];
    
    [_secondBtn autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:(SCREEN_Width/3.0)];
    [_secondBtn autoSetDimension:ALDimensionWidth toSize:(SCREEN_Width/3.0)];
    [_secondBtn autoSetDimension:ALDimensionHeight toSize:49];
    [_secondBtn autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_titleView];
    
    [_thirdBtn autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:(SCREEN_Width/3.0 * 2)];
    [_thirdBtn autoSetDimension:ALDimensionWidth toSize:(SCREEN_Width/3.0)];
    [_thirdBtn autoSetDimension:ALDimensionHeight toSize:49];
    [_thirdBtn autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_titleView];
    
}

- (void)firstBtnAction
{
    self.firstBtn.selected = YES;
    self.secondBtn.selected = NO;
    self.thirdBtn.selected = NO;
    
    CGFloat pageX = 0 * SCREEN_Width;
    [self.contentScrollView setContentOffset:CGPointMake(pageX, 0) animated:YES];
    
}

- (void)secondBtnAction
{
    self.firstBtn.selected = NO;
    self.secondBtn.selected = YES;
    self.thirdBtn.selected = NO;
    
    CGFloat pageX = 1 * SCREEN_Width;
    [self.contentScrollView setContentOffset:CGPointMake(pageX, 0) animated:YES];
}

- (void)thirdBtnAction
{
    self.firstBtn.selected = NO;
    self.secondBtn.selected = NO;
    self.thirdBtn.selected = YES;
    
    CGFloat pageX = 2 * SCREEN_Width;
    [self.contentScrollView setContentOffset:CGPointMake(pageX, 0) animated:YES];
}

#pragma mark -UIScrollViewDelegate
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    NSInteger index = scrollView.contentOffset.x / SCREEN_Width;
    
    if (self.index == 0) {
        if (index == 0) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformIdentity;
            }];
            
            self.firstBtn.selected = YES;
            self.secondBtn.selected=  NO;
            self.thirdBtn.selected = NO;
        }
        
        if (index == 1) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformMakeTranslation(SCREEN_Width/3.0, 0);
            }];
            
            self.firstBtn.selected = NO;
            self.secondBtn.selected=  YES;
            self.thirdBtn.selected = NO;
        }
        
        if (index == 2) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformMakeTranslation(SCREEN_Width/3.0 * 2, 0);
            }];
            
            self.firstBtn.selected = NO;
            self.secondBtn.selected=  NO;
            self.thirdBtn.selected = YES;
        }
    }
    
    if (self.index == 1) {
        
        if (index == 0) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformMakeTranslation(-SCREEN_Width/3.0, 0);
            }];
            
            self.firstBtn.selected = YES;
            self.secondBtn.selected=  NO;
            self.thirdBtn.selected = NO;
        }
        
        if (index == 1) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformIdentity;
            }];
            
            self.firstBtn.selected = NO;
            self.secondBtn.selected=  YES;
            self.thirdBtn.selected = NO;
        }
        
        if (index == 2) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformMakeTranslation(SCREEN_Width/3.0, 0);
            }];
            
            self.firstBtn.selected = NO;
            self.secondBtn.selected=  NO;
            self.thirdBtn.selected = YES;
        }
    }
    
    if (self.index == 2) {
        if (index == 0) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformMakeTranslation(-SCREEN_Width/3.0 * 2, 0);
            }];
            
            self.firstBtn.selected = YES;
            self.secondBtn.selected=  NO;
            self.thirdBtn.selected = NO;
        }
        
        if (index == 1) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformMakeTranslation(-SCREEN_Width/3.0, 0);
            }];
            
            self.firstBtn.selected = NO;
            self.secondBtn.selected=  YES;
            self.thirdBtn.selected = NO;
        }
        
        if (index == 2) {
            //
            
            [UIView animateWithDuration:AnimationInterval animations:^{
                self.underLineView.transform = CGAffineTransformIdentity;
            }];
            
            self.firstBtn.selected = NO;
            self.secondBtn.selected=  NO;
            self.thirdBtn.selected = YES;
        }
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [self scrollViewDidEndScrollingAnimation:scrollView];
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    [self scrollViewDidEndScrollingAnimation:scrollView];
//}

- (void)push
{
    CaiPushViewController *push = [[CaiPushViewController alloc] init];
    [self.navigationController pushViewController:push animated:YES];
}

@end

复制代码
  • CaiPushViewController
//
//  CaiPushViewController.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/12.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "CaiPushViewController.h"
#import "CaiFourthTableView.h"
#import "PureLayout.h"
#import "CaiCommon.h"

@interface CaiPushViewController ()

@property (nonatomic, strong) CaiFourthTableView *fourthTableView;

@end

@implementation CaiPushViewController

- (CaiFourthTableView *)fourthTableView
{
    if (!_fourthTableView) {
        _fourthTableView = [CaiFourthTableView newAutoLayoutView];
    }
    return _fourthTableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"push";
    self.view.backgroundColor = [UIColor purpleColor];
    
    [self setupUI];
}

/**
 *  UI
 */
- (void)setupUI
{
    [self.view addSubview:self.fourthTableView];
    [self.fourthTableView autoPinEdgeToSuperviewEdge:ALEdgeLeading];
    [self.fourthTableView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
    [self.fourthTableView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
    [self.fourthTableView autoPinEdgeToSuperviewEdge:ALEdgeTop];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_Width, 44)];
    headView.backgroundColor = [UIColor whiteColor];
    self.fourthTableView.tableHeaderView = headView;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 16, SCREEN_Width, 12)];
    label.text = @"cell类型为UITableViewCellStyleValue2";
    label.textColor = [UIColor purpleColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = FONT(12);
    [headView addSubview:label];
    
    UIView *line =[[UIView alloc] initWithFrame:CGRectMake(15, 44, SCREEN_Width - 15, 0.5)];
    line.backgroundColor = [UIColor lightGrayColor];
    [headView addSubview:line];
}
@end

复制代码
  • CaiFirstTableView.h
//
//  CaiFirstTableView.h
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol CaiPushDelegate <NSObject>

@optional
- (void)push;

@end

@interface CaiFirstTableView : UITableView

@property (nonatomic, weak) id<CaiPushDelegate>pushDelegate;

@end

复制代码
  • CaiFirstTableView.m
//
//  CaiFirstTableView.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "CaiFirstTableView.h"
#import "PureLayout/PureLayout.h"

@interface CaiFirstTableView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation CaiFirstTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.textLabel.text = @"first";
    
    UIView *line =[UIView newAutoLayoutView];
    line.backgroundColor = [UIColor lightGrayColor];
    [cell.contentView addSubview:line];
    [line autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:15];
    [line autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
    [line autoPinEdgeToSuperviewEdge:ALEdgeBottom];
    [line autoSetDimension:ALDimensionHeight toSize:0.5];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [UIColor whiteColor];
    label.text = @"    cell类型为UITableViewCellStyleDefault";
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:12];
    return label;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.pushDelegate && [self.pushDelegate respondsToSelector:@selector(push)]) {
        [self.pushDelegate push];
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end

复制代码
  • CaiSecondTableView.m
//
//  CaiSecondTableView.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "CaiSecondTableView.h"
#import "PureLayout.h"

@interface CaiSecondTableView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation CaiSecondTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = @"second";
    cell.detailTextLabel.text = @"cell类型为UITableViewCellStyleSubtitle";
    
    UIView *line =[UIView newAutoLayoutView];
    line.backgroundColor = [UIColor lightGrayColor];
    [cell.contentView addSubview:line];
    [line autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:15];
    [line autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
    [line autoPinEdgeToSuperviewEdge:ALEdgeBottom];
    [line autoSetDimension:ALDimensionHeight toSize:0.5];
    
    return cell;
}

@end

复制代码
  • CaiThirdTableView.m
//
//  CaiThirdTableView.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "CaiThirdTableView.h"
#import "PureLayout.h"

@interface CaiThirdTableView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation CaiThirdTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = @"third";
    cell.detailTextLabel.text = @"detail";
    
    UIView *line =[UIView newAutoLayoutView];
    line.backgroundColor = [UIColor lightGrayColor];
    [cell.contentView addSubview:line];
    [line autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:15];
    [line autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
    [line autoPinEdgeToSuperviewEdge:ALEdgeBottom];
    [line autoSetDimension:ALDimensionHeight toSize:0.5];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [UIColor whiteColor];
    label.text = @"    cell类型为UITableViewCellStyleValue1";
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:12];
    return label;
}

@end

复制代码
  • CaiFourthTableView.m
//
//  CaiFourthTableView.m
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/13.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#import "CaiFourthTableView.h"
#import "PureLayout.h"

@interface CaiFourthTableView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation CaiFourthTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = @"fourth";
    cell.detailTextLabel.text = @"detail";
    
    UIView *line =[UIView newAutoLayoutView];
    line.backgroundColor = [UIColor lightGrayColor];
    [cell.contentView addSubview:line];
    [line autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:15];
    [line autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
    [line autoPinEdgeToSuperviewEdge:ALEdgeBottom];
    [line autoSetDimension:ALDimensionHeight toSize:0.5];
    
    return cell;
}

@end

复制代码
  • CaiCommon.h

//
//  CaiCommon.h
//  LuckyCoderCai_ScrollViewTest
//
//  Created by luckyCoderCai on 16/9/11.
//  Copyright © 2016年 luckyCoderCai. All rights reserved.
//

#ifndef CaiCommon_h
#define CaiCommon_h

#define SCREEN_Width [UIScreen mainScreen].bounds.size.width
#define SCREEN_Height [UIScreen mainScreen].bounds.size.height

#define FONT(font) [UIFont systemFontOfSize:font]
#define BOLDFONT(bFont) [UIFont boldSystemFontOfSize:bFont]

#endif /* CaiCommon_h */

复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值