ios 日历简单制作和可选择某段特定时间NSCalendar 和NSDate

本文介绍了如何在iOS项目中创建一个简单的日历组件,用于活动报名。用户可以在当前时间之后的7天内选择活动日期。
摘要由CSDN通过智能技术生成

最近做项目需要制作一个活动报名的页面。其中需要定制一个简单的日历表来活动报名,大概效果
这里写图片描述
活动选择时间时根据当前时间之后7天的7天内可以活动报名

#define CURRENT_Date [NSDate date]
#import "CalendarVC.h"

@interface CalendarVC ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
{
    UILabel *_yearLabel;
    NSDate *_date;
    NSInteger _isCurrentMouth;// 0 当前月(默认)  -1 以前  1 后一个月  -1 后面不可用
    NSInteger _day;//当前日子;
    NSInteger _spaceDay;//当前月份活动天数;

}
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation CalendarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];


    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 60)];
    backView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:1];
    [self.view addSubview:backView];
    UIButton *lastButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 80, 30)];
    lastButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [lastButton setTitle:@"上一月" forState:UIControlStateNormal];
    [backView addSubview:lastButton];
    [lastButton addTarget:self action:@selector(clcikLastButton) forControlEvents:UIControlEventTouchUpInside];

    UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 85, 2, 80, 30)];
    [nextButton setTitle:@"下一月" forState:UIControlStateNormal];
    [backView addSubview:nextButton];
    nextButton.titleLabel.font = [UIFont systemFontOfSize:14]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值