Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ipad screen size #31

Closed
wants to merge 1 commit into from

3 participants

@valtrain

I made a few changes for my project to support iPad-sized calendars if you'd like to pick those up. It detects if it's iPad automatically, no client code has to change.

@klazuka klazuka closed this
@klazuka
Owner

Thanks, but I'm going to pass on making this change. I don't need iPad support, and so I don't have any kind of application that would exercise the functionality. I can't merge the changes unless I have a way of verifying the correctness both now and in the future as I make further changes to Kal.

@Radagan

Someone buy this man an iPad! Off to manually merge to support my Universal app... :^(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 30, 2011
  1. @valtrain

    Added support for iPad size

    valtrain authored
This page is out of date. Refresh to see the latest.
View
1  src/KalGridView.h
@@ -42,4 +42,5 @@
- (void)slideDown;
- (void)jumpToSelectedMonth; // see comment on KalView
++(CGSize) tileSize;
@end
View
27 src/KalGridView.m
@@ -17,8 +17,6 @@
#define SLIDE_UP 1
#define SLIDE_DOWN 2
-const CGSize kTileSize = { 46.f, 44.f };
-
static NSString *kSlideAnimationId = @"KalSwitchMonths";
@interface KalGridView ()
@@ -31,6 +29,22 @@ @implementation KalGridView
@synthesize selectedTile, highlightedTile, transitioning;
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
+ #define KAL_IPAD_VERSION (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+#else
+ #define KAL_IPAD_VERSION (NO)
+#endif
+
++(CGSize) tileSize
+{
+ if (KAL_IPAD_VERSION)
+ {
+ return CGSizeMake(110.f, 104.f);
+ }
+
+ return CGSizeMake(46.f, 44.f);
+}
+
- (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id<KalViewDelegate>)theDelegate
{
// MobileCal uses 46px wide tiles, with a 2px inner stroke
@@ -41,7 +55,9 @@ - (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id<KalVie
// to accomodate all 7 columns. The 7th day's 2px inner stroke
// will be clipped off the screen, but that's fine because
// MobileCal does the same thing.
- frame.size.width = 7 * kTileSize.width;
+ CGSize tileSize = [KalGridView tileSize];
+ if( frame.size.width < 7 * tileSize.width )
+ frame.size.width = 7 * tileSize.width;
if (self = [super initWithFrame:frame]) {
self.clipsToBounds = YES;
@@ -156,16 +172,17 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)swapMonthsAndSlide:(int)direction keepOneRow:(BOOL)keepOneRow
{
backMonthView.hidden = NO;
+ CGSize tileSize = [KalGridView tileSize];
// set initial positions before the slide
if (direction == SLIDE_UP) {
backMonthView.top = keepOneRow
- ? frontMonthView.bottom - kTileSize.height
+ ? frontMonthView.bottom - tileSize.height
: frontMonthView.bottom;
} else if (direction == SLIDE_DOWN) {
NSUInteger numWeeksToKeep = keepOneRow ? 1 : 0;
NSInteger numWeeksToSlide = [backMonthView numWeeks] - numWeeksToKeep;
- backMonthView.top = -numWeeksToSlide * kTileSize.height;
+ backMonthView.top = -numWeeksToSlide * tileSize.height;
} else {
backMonthView.top = 0.f;
}
View
12 src/KalMonthView.m
@@ -6,12 +6,11 @@
#import <CoreGraphics/CoreGraphics.h>
#import "KalMonthView.h"
#import "KalTileView.h"
+#import "KalGridView.h"
#import "KalView.h"
#import "KalDate.h"
#import "KalPrivate.h"
-extern const CGSize kTileSize;
-
@implementation KalMonthView
@synthesize numWeeks;
@@ -21,9 +20,10 @@ - (id)initWithFrame:(CGRect)frame
if ((self = [super initWithFrame:frame])) {
self.opaque = NO;
self.clipsToBounds = YES;
+ CGSize tileSize = [KalGridView tileSize];
for (int i=0; i<6; i++) {
for (int j=0; j<7; j++) {
- CGRect r = CGRectMake(j*kTileSize.width, i*kTileSize.height, kTileSize.width, kTileSize.height);
+ CGRect r = CGRectMake(j*tileSize.width, i*tileSize.height, tileSize.width, tileSize.height);
[self addSubview:[[[KalTileView alloc] initWithFrame:r] autorelease]];
}
}
@@ -55,8 +55,9 @@ - (void)showDates:(NSArray *)mainDates leadingAdjacentDates:(NSArray *)leadingAd
- (void)drawRect:(CGRect)rect
{
+ CGSize tileSize = [KalGridView tileSize];
CGContextRef ctx = UIGraphicsGetCurrentContext();
- CGContextDrawTiledImage(ctx, (CGRect){CGPointZero,kTileSize}, [[UIImage imageNamed:@"Kal.bundle/kal_tile.png"] CGImage]);
+ CGContextDrawTiledImage(ctx, (CGRect){CGPointZero,tileSize}, [[UIImage imageNamed:@"Kal.bundle/kal_tile.png"] CGImage]);
}
- (KalTileView *)firstTileOfMonth
@@ -88,7 +89,8 @@ - (KalTileView *)tileForDate:(KalDate *)date
- (void)sizeToFit
{
- self.height = 1.f + kTileSize.height * numWeeks;
+ CGSize tileSize = [KalGridView tileSize];
+ self.height = 1.f + tileSize.height * numWeeks;
}
- (void)markTilesForDates:(NSArray *)dates
View
22 src/KalTileView.m
@@ -5,10 +5,9 @@
#import "KalTileView.h"
#import "KalDate.h"
+#import "KalGridView.h"
#import "KalPrivate.h"
-extern const CGSize kTileSize;
-
@implementation KalTileView
@synthesize date;
@@ -34,22 +33,23 @@ - (void)drawRect:(CGRect)rect
UIColor *textColor = nil;
UIImage *markerImage = nil;
CGContextSelectFont(ctx, [font.fontName cStringUsingEncoding:NSUTF8StringEncoding], fontSize, kCGEncodingMacRoman);
-
- CGContextTranslateCTM(ctx, 0, kTileSize.height);
+
+ CGSize tileSize = [KalGridView tileSize];
+ CGContextTranslateCTM(ctx, 0, tileSize.height);
CGContextScaleCTM(ctx, 1, -1);
if ([self isToday] && self.selected) {
- [[[UIImage imageNamed:@"Kal.bundle/kal_tile_today_selected.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, kTileSize.width+1, kTileSize.height+1)];
+ [[[UIImage imageNamed:@"Kal.bundle/kal_tile_today_selected.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, tileSize.width+1, tileSize.height+1)];
textColor = [UIColor whiteColor];
shadowColor = [UIColor blackColor];
markerImage = [UIImage imageNamed:@"Kal.bundle/kal_marker_today.png"];
} else if ([self isToday] && !self.selected) {
- [[[UIImage imageNamed:@"Kal.bundle/kal_tile_today.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, kTileSize.width+1, kTileSize.height+1)];
+ [[[UIImage imageNamed:@"Kal.bundle/kal_tile_today.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, tileSize.width+1, tileSize.height+1)];
textColor = [UIColor whiteColor];
shadowColor = [UIColor blackColor];
markerImage = [UIImage imageNamed:@"Kal.bundle/kal_marker_today.png"];
} else if (self.selected) {
- [[[UIImage imageNamed:@"Kal.bundle/kal_tile_selected.png"] stretchableImageWithLeftCapWidth:1 topCapHeight:0] drawInRect:CGRectMake(0, -1, kTileSize.width+1, kTileSize.height+1)];
+ [[[UIImage imageNamed:@"Kal.bundle/kal_tile_selected.png"] stretchableImageWithLeftCapWidth:1 topCapHeight:0] drawInRect:CGRectMake(0, -1, tileSize.width+1, tileSize.height+1)];
textColor = [UIColor whiteColor];
shadowColor = [UIColor blackColor];
markerImage = [UIImage imageNamed:@"Kal.bundle/kal_marker_selected.png"];
@@ -71,8 +71,8 @@ - (void)drawRect:(CGRect)rect
const char *day = [dayText cStringUsingEncoding:NSUTF8StringEncoding];
CGSize textSize = [dayText sizeWithFont:font];
CGFloat textX, textY;
- textX = roundf(0.5f * (kTileSize.width - textSize.width));
- textY = 6.f + roundf(0.5f * (kTileSize.height - textSize.height));
+ textX = roundf(0.5f * (tileSize.width - textSize.width));
+ textY = 6.f + roundf(0.5f * (tileSize.height - textSize.height));
if (shadowColor) {
[shadowColor setFill];
CGContextShowTextAtPoint(ctx, textX, textY, day, n >= 10 ? 2 : 1);
@@ -83,7 +83,7 @@ - (void)drawRect:(CGRect)rect
if (self.highlighted) {
[[UIColor colorWithWhite:0.25f alpha:0.3f] setFill];
- CGContextFillRect(ctx, CGRectMake(0.f, 0.f, kTileSize.width, kTileSize.height));
+ CGContextFillRect(ctx, CGRectMake(0.f, 0.f, tileSize.width, tileSize.height));
}
}
@@ -92,7 +92,7 @@ - (void)resetState
// realign to the grid
CGRect frame = self.frame;
frame.origin = origin;
- frame.size = kTileSize;
+ frame.size = [KalGridView tileSize];
self.frame = frame;
[date release];
View
29 src/KalView.m
@@ -14,13 +14,26 @@ - (void)addSubviewsToContentView:(UIView *)contentView;
- (void)setHeaderTitleText:(NSString *)text;
@end
-static const CGFloat kHeaderHeight = 44.f;
static const CGFloat kMonthLabelHeight = 17.f;
@implementation KalView
@synthesize delegate, tableView;
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
+ #define KAL_IPAD_VERSION (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+#else
+ #define KAL_IPAD_VERSION (NO)
+#endif
+
+-(CGFloat) headerHeight
+{
+ if(KAL_IPAD_VERSION)
+ return 80.f;
+
+ return 44.f;
+}
+
- (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)theDelegate logic:(KalLogic *)theLogic
{
if ((self = [super initWithFrame:frame])) {
@@ -29,6 +42,8 @@ - (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)theDelegate logi
[logic addObserver:self forKeyPath:@"selectedMonthNameAndYear" options:NSKeyValueObservingOptionNew context:NULL];
self.autoresizesSubviews = YES;
self.autoresizingMask = UIViewAutoresizingFlexibleHeight;
+
+ const CGFloat kHeaderHeight = [self headerHeight];
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, frame.size.width, kHeaderHeight)] autorelease];
headerView.backgroundColor = [UIColor grayColor];
@@ -72,7 +87,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
const CGFloat kChangeMonthButtonWidth = 46.0f;
const CGFloat kChangeMonthButtonHeight = 30.0f;
const CGFloat kMonthLabelWidth = 200.0f;
- const CGFloat kHeaderVerticalAdjust = 3.f;
+ const CGFloat kHeaderVerticalAdjust = KAL_IPAD_VERSION ? 7.f : 3.f;
// Header background gradient
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Kal.bundle/kal_grid_background.png"]];
@@ -127,11 +142,15 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
NSArray *weekdayNames = [[[[NSDateFormatter alloc] init] autorelease] shortWeekdaySymbols];
NSUInteger firstWeekday = [[NSCalendar currentCalendar] firstWeekday];
NSUInteger i = firstWeekday - 1;
- for (CGFloat xOffset = 0.f; xOffset < headerView.width; xOffset += 46.f, i = (i+1)%7) {
- CGRect weekdayFrame = CGRectMake(xOffset, 30.f, 46.f, kHeaderHeight - 29.f);
+ CGSize tileSize = [KalGridView tileSize];
+ CGFloat columnWidth = tileSize.width;
+ CGFloat fontSize = KAL_IPAD_VERSION ? 20.f : 10.f;
+ const CGFloat kHeaderHeight = [self headerHeight];
+ for (CGFloat xOffset = 0.f; xOffset < headerView.width; xOffset += columnWidth, i = (i+1)%7) {
+ CGRect weekdayFrame = CGRectMake(xOffset, 30.f, columnWidth, kHeaderHeight - 29.f);
UILabel *weekdayLabel = [[UILabel alloc] initWithFrame:weekdayFrame];
weekdayLabel.backgroundColor = [UIColor clearColor];
- weekdayLabel.font = [UIFont boldSystemFontOfSize:10.f];
+ weekdayLabel.font = [UIFont boldSystemFontOfSize:fontSize];
weekdayLabel.textAlignment = UITextAlignmentCenter;
weekdayLabel.textColor = [UIColor colorWithRed:0.3f green:0.3f blue:0.3f alpha:1.f];
weekdayLabel.shadowColor = [UIColor whiteColor];
Something went wrong with that request. Please try again.