Xuni for IOS のドキュメント
日付コンテンツのカスタマイズ

Xuni Calendar コントロールを使用して、日付スロットにカスタムコンテンツを追加できます。それには、dayOfWeekSlotLoading イベントをサブスクライブし、これらの日付スロットの背景に画像などのカスタムコンテンツを適用します。この機能を使用して、カレンダーに天気関連の情報を表示できます。

次の図は、日付スロットにカスタムコンテンツを追加した後の Xuni Calendar です。このカレンダーには、さまざまなアイコンで天気関連の情報が表示されます。

次のコード例は、Objective-C で Xuni Calendar コントロールの日付スロットにカスタムコンテンツを追加する方法を示します。この例では、「クイックスタート」で作成したサンプルを使用します。

  1. ViewController.m ファイルの内容を次のコードに置き換えます。
    Objective-C
    コードのコピー
    #import "ViewController.h"
    #import "XuniCalendarKit/XuniCalendarKit.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController{
        NSArray *weatherIcon;
        NSArray *dotIcon;
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self setTitle:@"Custom Day Content"];
        
       
        weatherIcon = [[NSArray alloc] initWithObjects:@"sunny", @"cloudy", @"rainy", @"stomy", nil];
        dotIcon = [[NSArray alloc] initWithObjects:@"blue", @"red", @"green", nil];
        
        XuniCalendar *calendar = [[XuniCalendar alloc] initWithFrame:CGRectZero];
        calendar.delegate = self;
        calendar.dayOfWeekFormat = XuniDayOfWeekFormatDDDD;
        calendar.calendarFont = [UIFont systemFontOfSize:14];
        calendar.todayFont = [UIFont boldSystemFontOfSize:14];
        calendar.tag = 1;
        
        [self.view addSubview:calendar];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        
    }
    
    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        
        CGSize size = self.view.bounds.size;
        CGFloat width = fminf(size.width, size.height);
        XuniCalendar *calendar = (XuniCalendar *)[self.view viewWithTag:1];
        calendar.frame = CGRectMake(0, 55, width, width - 55);
    }
    
    - (void)dayOfWeekSlotLoading:(XuniCalendar *)sender args:(XuniCalendarDayOfWeekSlotLoadingEventArgs *)args {
        args.dayOfWeekSlot.font = args.isWeekend ? [UIFont italicSystemFontOfSize:11.0] : [UIFont boldSystemFontOfSize:11.0];
    }
    
    - (void)daySlotLoading:(XuniCalendar *)sender args:(XuniCalendarDaySlotLoadingEventArgs *)args {
        if (args.isAdjacentDay) {
            return;
        }
        
        NSInteger day = [[NSCalendar currentCalendar] components:NSCalendarUnitDay fromDate:args.date].day;
        CGRect rect = args.daySlot.frame;
        CGSize size = rect.size;
        CGRect rect1, rect2;
        XuniCalendarImageDaySlot *imageDaySlot = [[XuniCalendarImageDaySlot alloc] initWithCalendar:sender frame:rect];
        
        if (day >= 14 && day <= 23) {
            rect1 = CGRectMake(0, 0, size.height / 4, size.height / 4);
            rect2 = CGRectMake(size.width / 4, size.height / 5 * 2, size.width / 2, size.height / 2);
            
            imageDaySlot.dayTextRect = rect1;
            imageDaySlot.dayFont = [UIFont systemFontOfSize:9.0];
            imageDaySlot.imageRect = rect2;
            imageDaySlot.imageSource = [UIImage imageNamed:[weatherIcon objectAtIndex:(day % 4)]];
        }
        else {
            rect1 = CGRectMake(0, 0, size.width, size.height / 6 * 4);
            rect2 = CGRectMake(size.width / 2 - 6 / 2, size.height / 6 * 4, 6, 6);
            
            imageDaySlot.dayTextRect = rect1;
            imageDaySlot.imageRect = rect2;
            imageDaySlot.imageSource = [UIImage imageNamed:[dotIcon objectAtIndex:(day % 3)]];
        }
        
        args.daySlot = imageDaySlot;
    }
    @end
    

 

 


Copyright © GrapeCity inc. All rights reserved.