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
File renamed without changes.
10 changes: 10 additions & 0 deletions 21651145陈仪/project02/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
���ܣ���iPhone��ģ�������ϸ�������ѡ���ӡ��һ����������Ȼֻ�иı��ꡢ�²��б仯��

������˼��û�н���һ����ҵ����framework�ٵ��룬����ֱ�ӽ�CalMonth.h��CalMonth.m�ļ����ӽ�����

������ҵ����ϸ���붼��storyboard��ViewController.m�С�

��ʾ�����õ���UILabel�ؼ�����sizeThatFits��setFrame����ʵ������Ӧ������С��ʾ���ݡ�
�ؼ����ô������ӣ�ûֱ���ϵ�storyboard�ϡ���Ϊ�������������֪��Ϊʲô��������ʱ�򲻻�����Ӧ������С��ʾ���ݡ�

�õ�DatePick�ؼ�����value changed�¼��Ļص������ǣ�- (IBAction)onYearOrMonthChanged:(id)sender
Binary file not shown.
495 changes: 495 additions & 0 deletions 21651145陈仪/project02/iPhoneCal/iPhoneCal.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.
Binary file not shown.
15 changes: 15 additions & 0 deletions 21651145陈仪/project02/iPhoneCal/iPhoneCal/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// iPhoneCal
//
// Created by iOSChenYi on 16-10-15.
// Copyright (c) 2016年 ChenYi. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
46 changes: 46 additions & 0 deletions 21651145陈仪/project02/iPhoneCal/iPhoneCal/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AppDelegate.m
// iPhoneCal
//
// Created by iOSChenYi on 16-10-15.
// Copyright (c) 2016年 ChenYi. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
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 throttle down OpenGL ES frame rates. 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 inactive 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5023" systemVersion="13A603" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--class Prefix:identifier View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13A603" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<datePicker contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="date" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="zDV-cV-Sfy">
<rect key="frame" x="0.0" y="203" width="320" height="162"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<date key="date" timeIntervalSinceReferenceDate="498314468.63111901">
<!--2016-10-16 12:41:08 +0000-->
</date>
<timeZone key="timeZone" name="America/Los_Angeles">
<data key="data">
VFppZgAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAC5AAAABAAAABCepkign7sVkKCGKqChmveQ
y4kaoNIj9HDSYSYQ1v50INiArZDa/tGg28CQENzes6DdqayQ3r6VoN+JjpDgnneg4WlwkOJ+WaDjSVKQ
5F47oOUpNJDmR1gg5xJREOgnOiDo8jMQ6gccIOrSFRDr5v4g7LH3EO3G4CDukdkQ76/8oPBxuxDxj96g
8n/BkPNvwKD0X6OQ9U+ioPY/hZD3L4Sg+CiiEPkPZqD6CIQQ+viDIPvoZhD82GUg/chIEP64RyD/qCoQ
AJgpIAGIDBACeAsgA3EokARhJ6AFUQqQBkEJoAcw7JAHjUOgCRDOkAmtvyAK8LCQC+CvoAzZzRANwJGg
DrmvEA+priAQmZEQEYmQIBJ5cxATaXIgFFlVEBVJVCAWOTcQFyk2IBgiU5AZCRggGgI1kBryNKAb4heQ
HNIWoB3B+ZAesfigH6HbkCB2KyAhgb2QIlYNICNq2hAkNe8gJUq8ECYV0SAnKp4QJ/7toCkKgBAp3s+g
KupiECu+saAs036QLZ6ToC6zYJAvfnWgMJNCkDFnkiAycySQM0d0IDRTBpA1J1YgNjLokDcHOCA4HAUQ
OOcaIDn75xA6xvwgO9vJEDywGKA9u6sQPo/6oD+bjRBAb9ygQYSpkEJPvqBDZIuQRC+goEVEbZBF89Mg
Ry2KEEfTtSBJDWwQSbOXIErtThBLnLOgTNZqkE18laBOtkyQT1x3oFCWLpBRPFmgUnYQkFMcO6BUVfKQ
VPwdoFY11JBW5TogWB7xEFjFHCBZ/tMQWqT+IFvetRBchOAgXb6XEF5kwiBfnnkQYE3eoGGHlZBiLcCg
Y2d3kGQNoqBlR1mQZe2EoGcnO5BnzWagaQcdkGmtSKBq5v+Qa5ZlIGzQHBBtdkcgbq/+EG9WKSBwj+AQ
cTYLIHJvwhBzFe0gdE+kEHT/CaB2OMCQdt7roHgYopB4vs2gefiEkHqer6B72GaQfH6RoH24SJB+XnOg
f5gqkAABAAECAwEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
AQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
AQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA
</data>
</timeZone>
<connections>
<action selector="onYearOrMonthChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="jWx-bJ-Js4"/>
</connections>
</datePicker>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
29 changes: 29 additions & 0 deletions 21651145陈仪/project02/iPhoneCal/iPhoneCal/CalMonth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// CalMonth.h
// CalPrint
//
// Created by iOSChenYi on 16-10-2.
// Copyright (c) 2016年 ChenYi. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CalMonth : NSObject
@property NSUInteger year;
@property NSUInteger month;

//将这个月的每一行输出放到lines中,提高复用效率,并且供CalYear快速使用。
@property NSMutableArray *lines;
//是否有-j这个option。-j用来输出这个月每一天是这一年的第几天。
@property bool jFlag;

- (NSUInteger) numOfDay;
- (NSUInteger) weekDayOfFirstDay;
- (NSUInteger) indexOfFirstDay;
- (id) init;
- (id) initWithMonth:(NSUInteger)month withJFlag:(bool)flag;
- (id) initWithYear:(NSUInteger)year andMonth:(NSUInteger) month;
- (NSString *) toString;
- (NSDate *) date;
- (void) setLines;
@end
194 changes: 194 additions & 0 deletions 21651145陈仪/project02/iPhoneCal/iPhoneCal/CalMonth.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
//
// CalMonth.m
// CalPrint
//
// Created by iOSChenYi on 16-10-2.
// Copyright (c) 2016年 ChenYi. All rights reserved.
//

#import "CalMonth.h"

@implementation CalMonth

//计算一个月有多少天
- (NSUInteger) numOfDay
{
NSCalendar *cal=[NSCalendar currentCalendar];

NSDate *date=[self date];

NSRange range=[cal rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:date];
NSUInteger numOfDay=range.length;

return numOfDay;
}

//计算每个月第一天是这一周的第几天。星期日为第一天,星期一为第二天,依此类推。
- (NSUInteger) weekDayOfFirstDay
{
NSCalendar *cal=[NSCalendar currentCalendar];

NSDate *firstDay=[self date];
NSUInteger weekday=[cal ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:firstDay];

return weekday;
}

//计算每个月第一天是一年中的第几天
- (NSUInteger) indexOfFirstDay
{
NSCalendar *cal=[NSCalendar currentCalendar];

NSDate *firstDay=[self date];
NSUInteger index=[cal ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:firstDay];

return index;
}

- (id)init
{
self=[super init];
if(self)
{
NSDate *today=[NSDate date];
NSCalendar *cal=[NSCalendar currentCalendar];

//得到今天是哪一年哪一月。
NSDateComponents *comps=[cal components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:today];

[self setYear:[comps year]];
[self setMonth:[comps month]];

[self setLines];
}
return self;
}

- (id) initWithMonth:(NSUInteger) month withJFlag:(bool)flag
{
self=[super init];
if(self)
{
NSDate *today=[NSDate date];
NSCalendar *cal=[NSCalendar currentCalendar];

NSDateComponents *comps=[cal components:NSCalendarUnitYear fromDate:today];

[self setYear:[comps year]];
[self setMonth:month];
[self setJFlag:flag];

[self setLines];
}
return self;
}

- (id) initWithYear:(NSUInteger)year andMonth:(NSUInteger)month
{
self=[super init];
if(self)
{
[self setYear:year];
[self setMonth:month];

[self setLines];
}
return self;
}

//格式化输出这个月
- (NSString *) toString
{
NSMutableString *output=[NSMutableString stringWithFormat:@""];

NSArray *months=@[@"一", @"二", @"三",
@"四", @"五", @"六",
@"七", @"八", @"九",
@"十", @"十一", @"十二"];

//设置第一行最前面的空白
if ([self month]<=10) {
[output appendFormat:@" "];
} else {
[output appendFormat:@" "];
}
[output appendFormat:@"%@月 %d", [months objectAtIndex:[self month]-1], [self year]];

[output appendFormat:@"\n日 一 二 三 四 五 六\n"];

for(NSString *line in [self lines])
{
[output appendString:line];
}
//一个月可能输出只有五行数字,按照系统cal的习惯,必须有六行。
if ([[self lines] count]<6) {
[output appendString:@"\n"];
}
return output;
}

- (void) setLines
{
//初始化lines
_lines=[[NSMutableArray alloc] init];
NSMutableString *output=[NSMutableString stringWithFormat:@""];

unsigned long weekday=[self weekDayOfFirstDay];
unsigned long index=[self indexOfFirstDay];
unsigned long numOfDay=[self numOfDay];

//初始化第一行最前面的空白。
for(int i=0; i<weekday-1; ++i)
{
if([self jFlag])
{
[output appendString:@" "];
} else {
[output appendString:@" "];
}
}

for(int i=1; i<=numOfDay; ++i, ++weekday)
{
if ([self jFlag]) {
unsigned long num=i-1+index;
if (num<10)
{
[output appendString:@" "];

} else if(num<100)
{
[output appendString:@" "];
}
[output appendFormat:@"%lu ", num];
} else {
//设置一位数前面的一个空格
if (i<10) {
[output appendString:@" "];
}
[output appendFormat:@"%d ", i];
}

//如果是一行中的最后一天,或者这个月的最后一天,将其后的空格改为换行符。
if ((weekday % 7)==0 || i==numOfDay)
{
[output replaceCharactersInRange:NSMakeRange([output length]-1, 1) withString:@"\n"];
[[self lines] addObject:[output copy]];
[output setString:@""];
}
}
}

//返回这个月的第一天。
- (NSDate *) date
{
NSCalendar *cal=[NSCalendar currentCalendar];

NSDateComponents *comps=[[NSDateComponents alloc] init];
[comps setYear:[self year]];
[comps setMonth:[self month]];
[comps setDay:1];

return [cal dateFromComponents:comps];
}
@end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading