gpt4 book ai didi

ios - 在 iOS 中自定义 JTCalender 中的颜色?

转载 作者:行者123 更新时间:2023-11-28 21:17:18 25 4
gpt4 key购买 nike

我在 iOS 中使用 JTCalender。我想用相同的颜色制作日期、月份名称等标签的颜色。截至目前,某些日期是黑色的。

enter image description here

请建议我怎样才能做到这一点?

最佳答案

您可以使用 JTCalendar 委托(delegate)方法自定义日 View

- (UIView<JTCalendarDay> *)calendarBuildDayView:(JTCalendarManager *)calendar
{
JTCalendarDayView *view = [JTCalendarDayView new];
view.textLabel.font = [UIFont fontWithName:@"Avenir-Light" size:13];
view.textLabel.textColor = [UIColor blackColor];

return view;
}
- (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView
{
dayView.hidden = NO;

// Test if the dayView is from another month than the page
// Use only in month mode for indicate the day of the previous or next month
if([dayView isFromAnotherMonth]){
dayView.hidden = YES;
}
// Today
else if([_calendarManager.dateHelper date:[NSDate date] isTheSameDayThan:dayView.date]){
dayView.circleView.hidden = NO;
dayView.circleView.backgroundColor = [UIColor blueColor];
dayView.dotView.backgroundColor = [UIColor whiteColor];
dayView.textLabel.textColor = [UIColor whiteColor];
}
// Selected date
else if(_dateSelected && [_calendarManager.dateHelper date:_dateSelected isTheSameDayThan:dayView.date]){
dayView.circleView.hidden = NO;
dayView.circleView.backgroundColor = [UIColor redColor];
dayView.dotView.backgroundColor = [UIColor whiteColor];
dayView.textLabel.textColor = [UIColor whiteColor];
}
// Another day of the current month
else{
dayView.circleView.hidden = YES;
dayView.dotView.backgroundColor = [UIColor redColor];
dayView.textLabel.textColor = [UIColor blackColor];
}

// Your method to test if a date have an event for example
if([self haveEventForDay:dayView.date]){
dayView.dotView.hidden = NO;
}
else{
dayView.dotView.hidden = YES;
}
}

注意:代码在Objective C中,请使用Swift中的相应方法。

来源:https://github.com/jonathantribouharet/JTCalendar

编辑:(根据 Kglay Kophyo 的建议)您可以在 delegate 中更改月份的颜色。

- (UIView *)calendarBuildMenuItemView:(JTCalendarManager *)calendar 
{
UILabel *label = [UILabel new];
label.textColor = [UIColor redColor]; // your color return label;
}

关于ios - 在 iOS 中自定义 JTCalender 中的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40969226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com