All Projects → jezzmemo → Jjstockview

jezzmemo / Jjstockview

Licence: mit
iOS股票,课程表,表格控件

Projects that are alternatives of or similar to Jjstockview

Machine Learning Curriculum
💻 Make machines learn so that you don't have to struggle to program them; The ultimate list
Stars: ✭ 761 (+573.45%)
Mutual labels:  course, curriculum
Learn Machine Learning in 5 Months
This is the Curriculum to learn Machine Leaning from scratch to expert.
Stars: ✭ 51 (-54.87%)
Mutual labels:  course, curriculum
Stock Management System
An Introductory Stock Management System built on PHP, jQuery with AJAX in MVC pattern.
Stars: ✭ 95 (-15.93%)
Mutual labels:  stock
Freecodecamp.cn
FCC China open source codebase and curriculum. Learn to code and help nonprofits.
Stars: ✭ 36,576 (+32268.14%)
Mutual labels:  curriculum
Languagepod101 Scraper
Python scraper for Language Pods such as Japanesepod101.com 👹 🗾 🍣 Compatible with Japanese, Chinese, French, German, Italian, Korean, Portuguese, Russian, Spanish and many more! ✨
Stars: ✭ 104 (-7.96%)
Mutual labels:  course
30 Days Of Python 3.6
This is a soon-to-be archived project version of 30 Days of Python. The original tutorial still works but we have an updated version in the works right now.
Stars: ✭ 98 (-13.27%)
Mutual labels:  course
Softwaredesign
Introduction to Software Design with Java
Stars: ✭ 104 (-7.96%)
Mutual labels:  course
Cs234 Reinforcement Learning Winter 2019
My Solutions of Assignments of CS234: Reinforcement Learning Winter 2019
Stars: ✭ 93 (-17.7%)
Mutual labels:  course
Cvessentials
Tutorial Series (60 hour course): Essentials of computer vision
Stars: ✭ 111 (-1.77%)
Mutual labels:  course
100daysofcode With Python Course
Course materials and handouts for #100DaysOfCode in Python course
Stars: ✭ 1,391 (+1130.97%)
Mutual labels:  course
Sass Fundamentals
👨‍🏫 Mike's Sass Fundamentals Course
Stars: ✭ 107 (-5.31%)
Mutual labels:  course
Acm Icpc Preparation
ACM-ICPC Preparation Guide
Stars: ✭ 1,377 (+1118.58%)
Mutual labels:  curriculum
Yahoofinanceapi
A handy Yahoo! Finance api wrapper, based on .NET Standard 2.0
Stars: ✭ 99 (-12.39%)
Mutual labels:  stock
Hust Invictus
【分享】华中科技大学研究生课程资料
Stars: ✭ 105 (-7.08%)
Mutual labels:  course
Python For Absolute Beginners Course
Code samples and other handouts for our course.
Stars: ✭ 1,352 (+1096.46%)
Mutual labels:  course
Zvt
modular quant framework.
Stars: ✭ 1,801 (+1493.81%)
Mutual labels:  stock
Deep Learning Python
Intro to Deep Learning, including recurrent, convolution, and feed forward neural networks.
Stars: ✭ 94 (-16.81%)
Mutual labels:  curriculum
Nlp Thu
NLP Course Material & QA
Stars: ✭ 101 (-10.62%)
Mutual labels:  course
Kupi Terminal
Ccxt based, open source, customized, extendable trading platform that supports 130+ crypto exchanges.
Stars: ✭ 104 (-7.96%)
Mutual labels:  stock
Mns
Money never sleeps! IntelliJ IDEA平台插件. 支持查看股票实时行情. 支持美股, 港股, A股.
Stars: ✭ 113 (+0%)
Mutual labels:  stock

demo gif

JJStockView

模仿股票表格和课程表,左右滑动时,标题部分不动,表头右边和内容右边一起滑动,上下滑动时,表头不动,所有内容一起上下滑动

如何安装

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
    pod 'JJStockView'
end
$ pod install

如何使用

简单的使用示例:

- (NSUInteger)countForStockView:(JJStockView*)stockView{
    return 30;
}

- (UIView*)titleCellForStockView:(JJStockView*)stockView atRowPath:(NSUInteger)row{
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    label.text = [NSString stringWithFormat:@"标题:%ld",row];
    label.textColor = [UIColor grayColor];
    label.backgroundColor = [UIColor colorWithRed:223.0f/255.0 green:223.0f/255.0 blue:223.0f/255.0 alpha:1.0];
    label.textAlignment = NSTextAlignmentCenter;
    return label;
}

- (UIView*)contentCellForStockView:(JJStockView*)stockView atRowPath:(NSUInteger)row{
    
    UIView* bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 30)];
    bg.backgroundColor = row % 2 == 0 ?[UIColor whiteColor] :[UIColor colorWithRed:240.0f/255.0 green:240.0f/255.0 blue:240.0f/255.0 alpha:1.0];
    for (int i = 0; i < 10; i++) {
        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(i * 100, 0, 100, 30)];
        label.text = [NSString stringWithFormat:@"内容:%d",i];
        label.textAlignment = NSTextAlignmentCenter;
        [bg addSubview:label];
    }
    return bg;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"股票表格";
    self.stockView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
    [self.view addSubview:self.stockView];
}

- (JJStockView*)stockView{
    if(_stockView != nil){
        return _stockView;
    }
    _stockView = [JJStockView new];
    _stockView.dataSource = self;
    _stockView.delegate = self;
    return _stockView;
}

DataSource必须实现,注释解释了各自的作用

@protocol StockViewDataSource <NSObject>

@required
//内容的行数
- (NSUInteger)countForStockView:(JJStockView*)stockView;
//内容左边View
- (UIView*)titleCellForStockView:(JJStockView*)stockView atRowPath:(NSUInteger)row;
//内容右边可滑动View
- (UIView*)contentCellForStockView:(JJStockView*)stockView atRowPath:(NSUInteger)row;
@end

Delegate的实现都是可选的:

@protocol StockViewDelegate <NSObject>

@optional
//左上角的固定不动的View
- (UIView*)headRegularTitle:(JJStockView*)stockView;
//可滑动头部View
- (UIView*)headTitle:(JJStockView*)stockView;
//头部高度
- (CGFloat)heightForHeadTitle:(JJStockView*)stockView;
//内容高度
- (CGFloat)heightForCell:(JJStockView*)stockView atRowPath:(NSUInteger)row;
//点击每行事件
- (void)didSelect:(JJStockView*)stockView atRowPath:(NSUInteger)row;
@end

下面我用一张图来表现每个元素对应的方法:

code demo

这里有详细的Demo示例: https://github.com/jezzmemo/JJStockView/blob/master/JJStockView/DemoViewController.m

实现原理

  • 顶部不变的头部用heightForHeaderInSection显示,用标题和内容两部分组成,内容部分是用UIScrollView作为容器
  • 内容部分,用头部类似的结构,cellForRowAtIndexPath实现Cell,分成左右两边部分,左边UIView,右边用UIScrollView作为容器
  • 基于以上的结构,在任意一个UIScrollView滑动的时候,头部的UIScrollView和Cell右边的UIScrollView一起来联动,代码片段如下:
- (void)linkAgeScrollView:(UIScrollView*)sender{
    NSArray* visibleCells = [self.stockTableView visibleCells];
    for (JJStockViewCell* cell in visibleCells) {
        if (cell.rightContentScrollView != sender) {
            cell.rightContentScrollView.delegate = nil;//disable send scrollViewDidScroll message
            [cell.rightContentScrollView setContentOffset:CGPointMake(sender.contentOffset.x, 0) animated:NO];
            cell.rightContentScrollView.delegate = self;//enable send scrollViewDidScroll message
        }
    }
    if (sender != self.headScrollView) {
        self.headScrollView.delegate = nil;//disable send scrollViewDidScroll message
        [self.headScrollView setContentOffset:CGPointMake(sender.contentOffset.x, 0) animated:NO];
        self.headScrollView.delegate = self;//enable send scrollViewDidScroll message
    }
    
    _lastScrollX = sender.contentOffset.x;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].