美文网首页
中转--RecordViewController-

中转--RecordViewController-

作者: 香蕉你个菠萝 | 来源:发表于2018-06-21 18:30 被阅读14次

    //LXCalendar

    import "RecordViewController.m"

    //
    //  RecordViewController.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/6/21.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "RecordViewController.h"
    #import "RecordMainView.h"
    #import "RecordViewModel.h"
    
    @interface RecordViewController ()
    @property (nonatomic,strong) RecordMainView *mainView;
    @property (nonatomic,strong) RecordViewModel *viewModel;
    @end
    
    @implementation RecordViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    -(void)addChildView {
        [self.view addSubview:self.mainView];
    }
    
    -(void)updateViewConstraints {
        [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        [super updateViewConstraints];
    }
    
    -(RecordMainView *)mainView {
        if (!_mainView) {
            _mainView = [[RecordMainView alloc] initWithViewModel:self.viewModel];
        }
        return _mainView;
    }
    
    -(RecordViewModel *)viewModel {
        if (!_viewModel) {
            _viewModel = [[RecordViewModel alloc] init];
        }
        return _viewModel;
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end
    

    RecordMainView

    //
    //  RecordMainView.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/6/21.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "RecordMainView.h"
    #import "RecordViewModel.h"
    #import "RecordHeadCollectView.h"
    #import "RecordDiaryCell.h"
    
    @interface RecordMainView ()<UITableViewDelegate,UITableViewDataSource>
    
    @property (nonatomic,strong) RecordViewModel *viewModel;
    @property (nonatomic,strong) RecordHeadCollectView *headView;
    @property (nonatomic,strong) UITableView *tableView;
    @property (nonatomic,strong) NSMutableArray *diaryArray;//底部
    
    @property (nonatomic,strong) NSMutableArray *dayArray;//
    
    @end
    
    @implementation RecordMainView
    
    -(instancetype)initWithViewModel:(id<BaseViewModelProtocol>)viewModel {
        self.viewModel = (RecordViewModel *)viewModel;
        return [super initWithViewModel:self.viewModel];
    }
    
    -(void)bindViewModel {
        
        
    }
    
    -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.diaryArray.count;
    }
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 50;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        RecordDiaryCell * cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithUTF8String:object_getClassName([RecordDiaryCell class])]];
        
        return cell;
    }
    -(NSMutableArray *)diaryArray {
        if (!_diaryArray) {
            _diaryArray = [NSMutableArray arrayWithObjects:@"1",@"", @"",@"",@"",@"6",nil];
        }
        return _diaryArray;
    }
    -(void)setupViews {
        [self addSubview:self.tableView];
        [self setNeedsUpdateConstraints];
        [self updateConstraintsIfNeeded];
    }
    -(void)updateConstraints {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        [super updateConstraints];
    }
    
    -(RecordHeadCollectView *)headView {
        if (!_headView) {
            _headView = [[RecordHeadCollectView alloc] initWithViewModel:self.viewModel];
            _headView.backgroundColor = DEFAULT_YELLOW_COLOR;
    
            
        }
        return _headView;
    }
    
    -(UITableView *)tableView {
        if (!_tableView) {
            _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
            _tableView.delegate = self;
            _tableView.dataSource = self;
            _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            [_tableView registerClass:[RecordDiaryCell class] forCellReuseIdentifier:[NSString stringWithUTF8String:object_getClassName([RecordDiaryCell class])]];
            
            self.headView.frame = CGRectMake(0, 0, SCREEN_WIDTH, (SCREEN_WIDTH-70)/7*5);
            [_tableView setTableHeaderView:self.headView];
            
            if (@available(iOS 11.0, *)) {
                _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            }
        }
        return _tableView;
    }
    - (RecordViewModel *)viewModel {
        if (!_viewModel) {
            _viewModel = [[RecordViewModel alloc] init];
        }
        return _viewModel;
    }
    
    @end
    
    

    RecordHeadCollectView

    //
    //  RecordHeadCollectView.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/6/21.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "RecordHeadCollectView.h"
    #import "RecordViewModel.h"
    #import "RecordDayCollectionCell.h"
    
    #import "NSString+NCDate.h"
    #import "NSDate+GFCalendar.h"
    
    @interface RecordHeadCollectView ()<UICollectionViewDataSource,UICollectionViewDelegate>
    @property (nonatomic,strong) RecordViewModel *viewModel;
    @property (nonatomic,strong) UICollectionView *collectionView;
    @property (nonatomic,strong) NSMutableArray *dataArray;
    @end
    
    @implementation RecordHeadCollectView
    
    -(instancetype)initWithViewModel:(id<BaseViewModelProtocol>)viewModel {
        self.viewModel = (RecordViewModel *)viewModel;
        return [super initWithViewModel:self.viewModel];
    }
    -(void)bindViewModel {
        
    }
    
    -(NSMutableArray *)dataArray {
        if (!_dataArray) {
            _dataArray = [NSMutableArray array];
            
            NSInteger first = [[NSDate date] firstWeekDayInMonth];
            NSInteger totalDays = [[NSDate date] totalDaysInMonth];
            
            //排列是周天开始
            if (first != 7) {
                for (int i = 0; i < first; i++) {
                    [_dataArray addObject:@""];
                }
            }
           
            for (int j = 1; j <= totalDays; j++) {
                [_dataArray addObject:[NSString stringWithFormat:@"%d",j]];
            }
            
            NSLog(@"RecordCollect数据源->%@",_dataArray);
        
        }
        return _dataArray;
    }
    
    # pragma mark collectionView代理事件
    -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
        return self.dataArray.count;
    }
    
    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        RecordDayCollectionCell  *cell =[collectionView dequeueReusableCellWithReuseIdentifier:[NSString stringWithUTF8String:object_getClassName([RecordDayCollectionCell class])] forIndexPath:indexPath];
        cell.dayLabel.text = self.dataArray[indexPath.row];
        if (indexPath.row ==10) {
            cell.dayStatus = CollectionDayStatusToday;
        }else if (indexPath.row == 15){
            cell.dayStatus = CollectionDayStatusHaveDiary;
        }else {
            cell.dayStatus = CollectionDayStatusDefault;
        }
        return cell;
    }
    
    #pragma mark 图片点击
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        
    }
    
    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        return CGSizeMake((SCREEN_WIDTH-(14*0.1))/7, (SCREEN_WIDTH-70)/7);
    }
    - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    //layout协议
    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
        
        return 0.1f;
    }
    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
        
        return 0.1f;
    }
    
    -(UICollectionView *)collectionView {
        if (!_collectionView) {
            UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
            //设置滚动方向
            layout.scrollDirection = UICollectionViewScrollDirectionVertical;
            _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
            [layout setItemSize:CGSizeMake((SCREEN_WIDTH-(14*0.1))/7, (SCREEN_WIDTH-70)/7)];
            
            _collectionView.delegate = self;
            _collectionView.dataSource = self;
            _collectionView.pagingEnabled = NO;
            _collectionView.showsHorizontalScrollIndicator = NO;
            _collectionView.showsVerticalScrollIndicator = NO;
            _collectionView.backgroundColor = DEFAULT_YELLOW_COLOR;
            [_collectionView registerClass:[RecordDayCollectionCell class] forCellWithReuseIdentifier:[NSString stringWithUTF8String:object_getClassName([RecordDayCollectionCell class])]];
            
        }
        return _collectionView;
    }
    
    -(void)setupViews {
        [self addSubview:self.collectionView];
        [self setNeedsUpdateConstraints];
        [self updateConstraintsIfNeeded];
    }
    -(void)updateConstraints {
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        [super updateConstraints];
    }
    - (RecordViewModel *)viewModel {
        if (!_viewModel) {
            _viewModel = [[RecordViewModel alloc] init];
        }
        return _viewModel;
    }
    
    @end
    
    

    RecordDayCollectionCell.h

    //
    //  RecordDayCollectionCell.h
    //  DXYiGe
    //
    //  Created by JHT on 2018/6/21.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    typedef NS_ENUM(NSUInteger, CollectionDayStatus) {
        CollectionDayStatusDefault,
        CollectionDayStatusToday,
        CollectionDayStatusHaveDiary,
    };
    
    @interface RecordDayCollectionCell : UICollectionViewCell
    @property (nonatomic,strong) UILabel *dayLabel;
    @property (nonatomic,assign) CollectionDayStatus dayStatus;
    @end
    
    

    RecordDayCollectionCell.m

    //
    //  RecordDayCollectionCell.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/6/21.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "RecordDayCollectionCell.h"
    
    @implementation RecordDayCollectionCell
    
    -(UILabel *)dayLabel {
        if (!_dayLabel) {
            _dayLabel = [[UILabel alloc] init];
            _dayLabel.font = [UIFont systemFontOfSize:12];
            _dayLabel.textAlignment = NSTextAlignmentCenter;
            _dayLabel.layer.cornerRadius = (SCREEN_WIDTH-120)/14;
            _dayLabel.layer.masksToBounds = YES;
            _dayLabel.backgroundColor = DEFAULT_YELLOW_COLOR;
            
        }
        return _dayLabel;
    }
    -(void)setDayStatus:(CollectionDayStatus)dayStatus {
        
        switch (dayStatus) {
            case CollectionDayStatusDefault:
            {
                
            }
                break;
            case CollectionDayStatusToday:
            {
                _dayLabel.backgroundColor = [UIColor whiteColor];
            }
                break;
            case CollectionDayStatusHaveDiary:
            {
                _dayLabel.layer.borderWidth = 1.0f;
                _dayLabel.layer.borderColor = [UIColor whiteColor].CGColor;
            }
                break;
            default:
                break;
        }
    }
    -(instancetype)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
            self.contentView.backgroundColor = DEFAULT_YELLOW_COLOR;
            [self addSubview:self.dayLabel];
            [self setNeedsUpdateConstraints];
            [self updateConstraintsIfNeeded];
        }
        return self;
    }
    
    -(void)updateConstraints {
        [self.dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.contentView);
            make.size.mas_offset(CGSizeMake((SCREEN_WIDTH-120)/7, (SCREEN_WIDTH-120)/7));
        }];
        [super updateConstraints];
    }
    
    @end
    
    

    NSDate+GFCalendar.h

    
    #import <Foundation/Foundation.h>
    
    @interface NSDate (GFCalendar)
    
    /**
     *  获得当前 NSDate 对象对应的日子
     */
    - (NSInteger)dateDay;
    
    /**
     *  获得当前 NSDate 对象对应的月份
     */
    - (NSInteger)dateMonth;
    
    /**
     *  获得当前 NSDate 对象对应的年份
     */
    - (NSInteger)dateYear;
    
    /**
     *  获得当前 NSDate 对象的上个月的某一天(此处定为15号)的 NSDate 对象
     */
    - (NSDate *)previousMonthDate;
    
    /**
     *  获得当前 NSDate 对象的下个月的某一天(此处定为15号)的 NSDate 对象
     */
    - (NSDate *)nextMonthDate;
    
    /**
     *  获得当前 NSDate 对象对应的月份的总天数
     */
    - (NSInteger)totalDaysInMonth;
    
    /**
     *  获得当前 NSDate 对象对应月份当月第一天的所属星期
     */
    - (NSInteger)firstWeekDayInMonth;
    
    @end
    
    

    NSDate+GFCalendar.m

    
    #import "NSDate+GFCalendar.h"
    
    @implementation NSDate (GFCalendar)
    
    - (NSInteger)dateDay {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSDateComponents *components = [calendar components:NSCalendarUnitDay fromDate:self];
        return components.day;
    }
    
    - (NSInteger)dateMonth {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSDateComponents *components = [calendar components:NSCalendarUnitMonth fromDate:self];
        return components.month;
    }
    
    - (NSInteger)dateYear {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSDateComponents *components = [calendar components:NSCalendarUnitYear fromDate:self];
        return components.year;
    }
    
    - (NSDate *)previousMonthDate {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        
        NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:self];
        components.day = 15; // 定位到当月中间日子
        
        if (components.month == 1) {
            components.month = 12;
            components.year -= 1;
        } else {
            components.month -= 1;
        }
        
        NSDate *previousDate = [calendar dateFromComponents:components];
        
        return previousDate;
    }
    
    - (NSDate *)nextMonthDate {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        
        NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:self];
        components.day = 15; // 定位到当月中间日子
        
        if (components.month == 12) {
            components.month = 1;
            components.year += 1;
        } else {
            components.month += 1;
        }
        
        NSDate *nextDate = [calendar dateFromComponents:components];
        
        return nextDate;
    }
    
    - (NSInteger)totalDaysInMonth {
        NSInteger totalDays = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:self].length;
        return totalDays;
    }
    
    - (NSInteger)firstWeekDayInMonth {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        
        NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:self];
        components.day = 1; // 定位到当月第一天
        NSDate *firstDay = [calendar dateFromComponents:components];
        
        // 默认一周第一天序号为 1 ,而日历中约定为 0 ,故需要减一
        NSInteger firstWeekday = [calendar ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitWeekOfMonth forDate:firstDay] - 1;
        
        return firstWeekday;
    }
    
    @end
    
    

    NSString+NCDate.h

    
    #import <Foundation/Foundation.h>
    
    @interface NSString (NCDate)
    +(NSString *)timeIntervalFromTimeStr:(NSString *)timeStr; //时间转换为时间戳
    +(NSString *)formateDate:(NSString *)string;//时间戳转换为时间
    +(NSInteger)getNowInterVal;//获取当前的时间戳
    +(NSString *)getNowTime;//获取当前的时间字符串
    +(NSString *)formateDateToDay:(NSString *)string;//时间戳转换为时间
    +(NSString *)formateDateOnlyYueri:(NSString *)string;//时间戳转换为时间
    +(NSString *)formateDateOnlyShifen:(NSString *)string;//时间戳转换为时间
    
    +(NSDate *)dateFromTimeStr:(NSString *)timeStr;//年月日转换为date;
    +(NSString *)ret32bitString;//随机的32位字符串
    @end
    
    

    NSString+NCDate.m

    
    #import "NSString+NCDate.h"
    
    @implementation NSString (NCDate)
    +(NSString *)timeIntervalFromTimeStr:(NSString *)timeStr{
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        // 设置日期格式(为了转换成功)
        fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        // NSString * -> NSDate *
        NSDate *date = [fmt dateFromString:timeStr];
        
        return [NSString stringWithFormat:@"%.f",date.timeIntervalSince1970 *1000];
    }
    +(NSString *)formateDate:(NSString *)string{
        NSTimeInterval second = string.longLongValue / 1000.0; //毫秒需要除
        
        // 时间戳 -> NSDate *
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
        //    NSLog(@"%@", date);
        
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"yyyy-MM-dd HH:mm";
        
        NSString *stringNew = [fmt stringFromDate:date];
        return stringNew;
    }
    +(NSString *)formateDateToDay:(NSString *)string{
        NSTimeInterval second = string.longLongValue / 1000.0; //毫秒需要除
        
        // 时间戳 -> NSDate *
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
        //    NSLog(@"%@", date);
        
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"yyyy-MM-dd";
        
        NSString *stringNew = [fmt stringFromDate:date];
        return stringNew;
    }
    
    +(NSString *)formateDateOnlyYueri:(NSString *)string{
        NSTimeInterval second = string.longLongValue / 1000.0; //毫秒需要除
        
        // 时间戳 -> NSDate *
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
        //    NSLog(@"%@", date);
        
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"MM-dd";
        
        NSString *stringNew = [fmt stringFromDate:date];
        return stringNew;
    }
    +(NSString *)formateDateOnlyShifen:(NSString *)string{
        
        NSTimeInterval second = string.longLongValue / 1000.0; //毫秒需要除
        
        // 时间戳 -> NSDate *
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
        //    NSLog(@"%@", date);
        
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"HH:mm";
        
        NSString *stringNew = [fmt stringFromDate:date];
        return stringNew;
    }
    +(NSInteger)getNowInterVal{
        NSDate  *date = [NSDate date];
        return date.timeIntervalSince1970 * 1000; //乘以1000为毫秒
    }
    +(NSString *)getNowTime{
        NSDate  *date = [NSDate date];
        
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        // 设置日期格式(为了转换成功)
        fmt.dateFormat = @"yyyy-MM-dd";
        NSString *dateStr =[fmt stringFromDate:date];
        return dateStr;
    }
    +(NSDate *)dateFromTimeStr:(NSString *)timeStr{
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        // 设置日期格式(为了转换成功)
        [fmt setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
        fmt.dateFormat = @"yyyy-MM-dd";
        // NSString * -> NSDate *
        NSDate *date = [fmt dateFromString:timeStr];
        return date;
    }
    
    +(NSString *)ret32bitString
    
    {
        
        char data[32];
        
        for (int x=0;x<32;data[x++] = (char)('A' + (arc4random_uniform(26))));
        
        return [[NSString alloc] initWithBytes:data length:32 encoding:NSUTF8StringEncoding];
        
    }
    @end
    
    

    相关文章

      网友评论

          本文标题:中转--RecordViewController-

          本文链接:https://www.haomeiwen.com/subject/fkfcyftx.html