当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS实现一个简易日历代码

iOS实现一个简易日历代码

2019年07月24日  | 移动技术网IT编程  | 我要评论

nuckily,神奇动物在哪里下载,郎溪二手房网

日历一般都是用uicollectionview进行开发的,相关demo也很多,这里就讲一个我最近写的玩的demo,由于时间原因没来得及加年历和周历,一个月历的小demo,随着月份天数的不同,自动改变日历的高。

代理部分:

@protocol kjcalendardelegate <nsobject>

/**
 随着每个月的天数不一样而改变高度

 @param height 日历高度
 */
- (void)calendarviewheightchange:(cgfloat)height;


/**
 当前展示的年和月,当类型是年历的时候,只返回年

 @param year 年
 @param month 月
 */
- (void)currentshowyear:(nsinteger)year withmonth:(nsinteger)month;


/**
 选中的时间

 @param solar 阳历
 @param lunar 农历
 */
- (void)selectsolardate:(nsstring *)solar withlunar:(nsstring *)lunar;

@end

这个当时创建文件的时候,没注意,kjcalendar写成了kjcanlendar,抱歉。。。

下面是可自定义的部分:

//======以下属性可自定义======

//背景颜色
@property (strong, nonatomic) uicolor *bgcolor;
//weekview背景色 默认clearcolor
@property (strong, nonatomic) uicolor *weekcolor;
//选择状态下的背景颜色
@property (strong, nonatomic) uicolor *selectbgcolor;
//选择状态下的字体颜色
@property (strong, nonatomic) uicolor *selecttitlecolor;
//普通状态下公历字体颜色
@property (strong, nonatomic) uicolor *normaldatetitlecolor;
//普通状态下农历字体颜色
@property (strong, nonatomic) uicolor *normallunertitlecolor;
//今天的字体颜色
@property (strong, nonatomic) uicolor *todaytitlecolor;
//今天选择状态下的背景颜色
@property (strong, nonatomic) uicolor *todayselectbgcolor;
//今天选择状态下的字体颜色
@property (strong, nonatomic) uicolor *todayselecttitlecolor;
//距屏幕左右间隔,默认8
@property (assign, nonatomic) cgfloat screeninspace;
//每行(item)的高度,设置的高度不能大于宽度,宽度的来源是屏幕的宽减去左右间隔除以7得到
@property (assign, nonatomic) cgfloat rowheight;
//设置是否显示阴历 yes-显示 no-隐藏 默认yes
@property (assign, nonatomic) bool isshowlunar;
//公历字体 默认system 13
@property (strong, nonatomic) uifont *datefont;
//农历字体 默认system 8
@property (strong, nonatomic) uifont *lunerfont;
//选中时公历字体 默认 [uifont boldsystemfontofsize:13.0f];
@property (strong, nonatomic) uifont *dateselectfont;
//选中时农历字体 默认 [uifont boldsystemfontofsize:8.0f];
@property (strong, nonatomic) uifont *lunerselectfont;

使用也很简单:

//高度是根据日历的月份天数决定的
  self.calview = [[kjcanlendarview alloc] initwithy:0 withnavc:yes andleastyear:0];
  self.calview.kjdelegate = self;

  [self.calview showkjcalendarinctrl:self];

每个属性都有默认值,需要改变赋值即可,当然啦,设置字体时,要调整背景圆圈的大小以及rouheight的大小,具体的下面我给出demo,就不多说了,大家就随便看看,写的很随意,希望能帮到大家。

demo:

效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网