Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
534 changes: 534 additions & 0 deletions 21651076艾兴/project02/Calendar/Calendar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions 21651076艾兴/project02/Calendar/Calendar/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
// Calendar
//
// Created by ax on 16/10/20.
// Copyright © 2016年 aixing. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

54 changes: 54 additions & 0 deletions 21651076艾兴/project02/Calendar/Calendar/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// AppDelegate.m
// Calendar
//
// Created by ax on 16/10/20.
// Copyright © 2016年 aixing. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor yellowColor];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
13 changes: 13 additions & 0 deletions 21651076艾兴/project02/Calendar/Calendar/CalendarView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CalendarView.h
// Calendar
//
// Created by ax on 16/10/20.
// Copyright © 2016年 aixing. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface CalendarView : UIView

@end
221 changes: 221 additions & 0 deletions 21651076艾兴/project02/Calendar/Calendar/CalendarView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
//
// CalendarView.m
// Calendar
//
// Created by ax on 16/10/20.
// Copyright © 2016年 aixing. All rights reserved.
//

#import "CalendarView.h"
#define ROW 6

@interface CalendarView()
@property (nonatomic, strong) NSCalendar *cal;
@property (nonatomic) NSInteger days;
@end

@implementation CalendarView
{
CGPoint calStart;
NSInteger monthCal[6][7];
}
- (instancetype)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
self.cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
for(int i=0; i<6; i++)
{
for(int j=0;j<7;j++)
{
monthCal[i][j] = 0;
}
}
}
return self;
}

- (void)drawRect:(CGRect)rect
{
[self drawTitle];
[self setMonthCal];
UIFont *font = [UIFont systemFontOfSize:13 weight:12];
NSDictionary* attributes = @{NSFontAttributeName : font};
NSString *strToBeDraw = [[NSString alloc] init];
CGSize spaceSize = [@" " sizeWithAttributes:attributes];
CGFloat fixedX = calStart.x;
for(int i = 0; i < 6; i++)
{
for(int j = 0; j < 7; j++)
{
if(monthCal[i][j] != 0)
{
strToBeDraw = [self getDayString:monthCal[i][j]];
}
else
{
strToBeDraw = @" ";
}
[strToBeDraw drawAtPoint:calStart withAttributes:attributes];
calStart.x += spaceSize.width*2;
}
calStart.x = fixedX;
calStart.y += spaceSize.height;
}

}

- (void)setMonthCal
{
NSInteger j = [self getFirstDate] - 1;
NSInteger days = 1;
for(NSInteger i=0;i<6;i++)
{
for(; j<7;j++)
{
if(days <=self.days)
{
monthCal[i][j] = days;
days++;
}
}
j = 0;
}
}

- (NSString*)getDayString:(NSInteger)day
{
if(day<10)
{
NSMutableString *str = [NSMutableString stringWithFormat:@" %ld",day];
return [NSString stringWithString:str];
}
else
{
return [NSString stringWithFormat:@" %ld",day];
}
}

- (void)drawTitle
{
UIFont *font = [UIFont systemFontOfSize:18 weight:20];
NSDictionary* attributes = @{NSFontAttributeName : font};
CGSize textSize = [@"2016" sizeWithAttributes:attributes];

UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0.25 * self.frame.size.height, self.frame.size.width, textSize.height)];
title.backgroundColor = [UIColor clearColor];
title.textColor = [UIColor blackColor];
title.textAlignment = NSTextAlignmentCenter;
title.text = [self getTitle];
[self addSubview:title];

CGSize calSize = [@"00 00 00 00 00 00 00" sizeWithAttributes:attributes];
CGPoint startPoint = {(self.frame.size.width - calSize.width) / 2, title.frame.origin.y+title.frame.size.height + ROW};
UILabel *weekTitle = [[UILabel alloc] initWithFrame:CGRectMake(startPoint.x, startPoint.y, calSize.width, calSize.height)];
weekTitle.backgroundColor = [UIColor clearColor];
weekTitle.textColor = [UIColor blackColor];
weekTitle.textAlignment = NSTextAlignmentCenter;
weekTitle.text = @"日 一 二 三 四 五 六";
[self addSubview:weekTitle];

CGFloat y = weekTitle.frame.origin.y;
CGFloat h = weekTitle.frame.size.height;
calStart.x = weekTitle.frame.origin.x+ROW*4;
calStart.y = y+h+ROW;
}

- (NSInteger)getFirstDate
{
NSDate *today = [NSDate date];
NSInteger month = [self.cal component:NSCalendarUnitMonth fromDate:today];
NSInteger year = [self.cal component:NSCalendarUnitYear fromDate:today];
NSDateComponents *component = [[NSDateComponents alloc] init];
[component setDay:1];
[component setMonth:month];
[component setYear:year];
NSDate *firstDay = [self.cal dateFromComponents:component];
self.days = [self.cal rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:firstDay].length;
NSInteger weekday = [self.cal component:NSCalendarUnitWeekday fromDate:firstDay];
return weekday;
}

- (NSString *)getTitle
{
NSMutableString *title = [[NSMutableString alloc] init];
NSDate *today = [NSDate date];
NSInteger month = [self.cal component:NSCalendarUnitMonth fromDate:today];
NSInteger year = [self.cal component:NSCalendarUnitYear fromDate:today];
title = [NSMutableString stringWithString:[self convert:month]];
[title appendString:@" "];
[title appendString:[NSMutableString stringWithFormat:@"%ld",(long)year]];
return title;
}

-(NSString*)convert:(NSInteger) month
{
NSString *m = [[NSString alloc] init];
switch (month) {
case 1:{
m = @"January";
break;}

case 2:{
m = @"February";
break;}

case 3:{
m = @"March";
break;
}

case 4:{
m = @"April";
break;
}

case 5:{
m = @"May";
break;
}

case 6:{
m = @"June";
break;
}

case 7:{
m = @"July";
break;
}

case 8:{
m = @"August";
break;
}

case 9:{
m = @"September";
break;
}

case 10:{
m = @"October";
break;
}

case 11:{
m = @"November";
break;
}

case 12:{
m = @"December";
break;
}

default:
break;
}
return m;
}
@end
Loading