iOS 定制日历

1.开发过程

2.感言



   由于app的需要,我们需要在app上放上一个定制的日历,开始以为很好解决,在网上看了许多demo,都不理想,为此焦头烂额了几天(一直在研究),最后终于决定自己写一个,压力好大 啊.下面我来说一下我坐日历的思路(算是取巧);

    xcode为我们提供了三个方法,我们可以通过此方法来获取当前的月份的长度,还可以获取当前月的第一天是星期几,日历的话我们必须确定具体的星期(系统时间的话打印出来的会和实际的差8个小时,后面我会粘出来)

  获取了系统的时间之后,根据系统自带的api获取本月天数和每月第一天的星期数,本月日历表建好,下个月的话,我会去处理本地时间,里面的月份+1,这样就可以获取下个月的日历了(本人测试可行),依次类推,就完成了一个无限的日历表了.下面上代码;



@interface LooKForProjectViewController ()
{
    NSCalendar *myCalendar;
    NSRange monthRange;
    int     currentDayIndexOfMonth;
    int     firstDayIndexOfWeek;
    UIScrollView * scroll;
    int      monthCount;//月份;
    UILabel * year_label;//显示年份;
    UIView * date_view;//日历背景图;
    NSString * myNewDate_str;//取处理完成之后的时间字符串;
    
}
@end

@implementation LooKForProjectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    scroll.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height + 5);
    scroll.backgroundColor = MY_GROUND_COLOR;
    scroll.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scroll];
    year_label = [[UILabel alloc]initWithFrame:CGRectMake(([[UIScreen mainScreen]bounds].size.width - 100)/2, 10, 100, 20)];
    [scroll addSubview:year_label];
    
    
    //下个月
    UIButton * next_month_button = [UIButton buttonWithType:UIButtonTypeSystem];
    next_month_button.frame = CGRectMake(220 , 10, 50, 20);
    [next_month_button setTitle:@"下个月" forState:UIControlStateNormal];
    [next_month_button addTarget:self action:@selector(showTheNextMonth:) forControlEvents:UIControlEventTouchUpInside];
    [scroll addSubview:next_month_button];
    
    //初始化日历;设置为公历;
    myCal

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值