klazuka / Kal

A calendar component for the iPhone (the UI is designed to match MobileCal)
http://www.thepolypeptides.com
1.22k stars 345 forks source link

iOS7 #94

Open Tippit opened 10 years ago

Tippit commented 10 years ago

KalTileView.m CGContextSelectFont sizeWithFont CGContextShowTextAtPoint Are deprecated in iOS 7 can you help please

JackJackBauer commented 10 years ago

Just use UILabel instead. Works like a charm. Here's the code I'm using for the date in KalTileView.m:

- (void)drawRect:(CGRect)rect...

NSUInteger n = [self.date day];
NSString *dayText = [NSString stringWithFormat:@"%lu", (unsigned long)n];

dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, adjustDateText, kTileSize.width, 20.)];
[dateLabel setBackgroundColor:[UIColor clearColor]];
dateLabel.textAlignment = NSTextAlignmentCenter;
NSDictionary *attrib = @{NSForegroundColorAttributeName : textColor,
                         NSFontAttributeName : font};

NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:dayText attributes:attrib];

dateLabel.attributedText = attribString;

[self addSubview:dateLabel];

where adjustDateText is set to adjust the horizontal position according the device used (i.e. 3.5", 4" or iPad).

Tippit commented 10 years ago

Thank´s you're awesome ;)

jas54 commented 10 years ago

@JackJackBauer: Can you please share how the variable "adjustDateText" has been initialized with device dependant values

JackJackBauer commented 10 years ago

Sure. I'm basically just going through some tests for devices and set the variable accordingly:

in - (void)drawRect:(CGRect)rect I set NSString *device = [[UIScreen mainScreen] bounds].size.height > 480 ? @"iPhone5":@"iPhone";. You can use something like if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) device = [ResourceManager sharedResourceManager].isLandscape ? device = @"iPadLandscape" : device = @"iPadPortrait"; to check for iPad-layouts.

I then set a bunch of layout-variables:

float adjustDateText = 2.f; if ([device isEqualToString:@"iPhone5"]) { ... adjustDateText = 5.f; } else if ([device isEqualToString:@"iPadLandscape"]) { ... adjustDateText = 13.f; }

And while we're at it: In fact I'm even checking for my custom 6-weeks-layout there and adjust for that too (I hated the wasted display-area for moths with just 5 weeks vs. those with 6 weeks...)

BOOL is6Weeks = self.numWeeks > 5 ? TRUE : FALSE;

where I passed the number of weeks (lines) in the current month from KalGridViews - (NSInteger)numberOfWeeksInDisplay { return (NSInteger) ceilf( ([logic.daysInFinalWeekOfPreviousMonth count] + [logic.daysInSelectedMonth count] + [logic.daysInFirstWeekOfFollowingMonth count])/ 7.f); } though KalMonthView.m

BTW the whole layout is easily customizable to a iOS7-like flat layout with the proper use of flat images and fonts. :-)

jas54 commented 10 years ago

thanks for the response.

But unfortunately this method is only working for the initial month view in the calendar. for the next month or previous month views, the date texts are overlapping. Is there any reset need to the label frame?

JackJackBauer commented 10 years ago

Hmm... I do not see any overlapping. But then I worked with the project and customized it for about 2 1/2 years now so there really isn't much left from the original ;-)

As I see it, when you make the changes to KalTileView.m it should affect all instances of those - i.e. all tiles. Not just those of the initial month, because all tiles are based on KalTileView.

What do you show in the tiles? Just the date as a number? What does it look like when these are overlapping?