diff --git a/GLTapLabelDemo.xcodeproj/project.xcworkspace/xcshareddata/GLTapLabelDemo.xccheckout b/GLTapLabelDemo.xcodeproj/project.xcworkspace/xcshareddata/GLTapLabelDemo.xccheckout
new file mode 100644
index 0000000..8f60ad7
--- /dev/null
+++ b/GLTapLabelDemo.xcodeproj/project.xcworkspace/xcshareddata/GLTapLabelDemo.xccheckout
@@ -0,0 +1,41 @@
+
+
+
+
+ IDESourceControlProjectFavoriteDictionaryKey
+
+ IDESourceControlProjectIdentifier
+ 8A17BD83-864D-4CFD-B4D5-575522C87497
+ IDESourceControlProjectName
+ GLTapLabelDemo
+ IDESourceControlProjectOriginsDictionary
+
+ B9A878C4-EB96-4B33-A17C-AE108FBB9986
+ ssh://github.com/ibrahimkteish/GLTapLabelDemo.git
+
+ IDESourceControlProjectPath
+ GLTapLabelDemo.xcodeproj/project.xcworkspace
+ IDESourceControlProjectRelativeInstallPathDictionary
+
+ B9A878C4-EB96-4B33-A17C-AE108FBB9986
+ ../..
+
+ IDESourceControlProjectURL
+ ssh://github.com/ibrahimkteish/GLTapLabelDemo.git
+ IDESourceControlProjectVersion
+ 110
+ IDESourceControlProjectWCCIdentifier
+ B9A878C4-EB96-4B33-A17C-AE108FBB9986
+ IDESourceControlProjectWCConfigurations
+
+
+ IDESourceControlRepositoryExtensionIdentifierKey
+ public.vcs.git
+ IDESourceControlWCCIdentifierKey
+ B9A878C4-EB96-4B33-A17C-AE108FBB9986
+ IDESourceControlWCCName
+ GLTapLabelDemo
+
+
+
+
diff --git a/GLTapLabelDemo/GLTapLabel.m b/GLTapLabelDemo/GLTapLabel.m
index 47358dd..1c38e74 100644
--- a/GLTapLabelDemo/GLTapLabel.m
+++ b/GLTapLabelDemo/GLTapLabel.m
@@ -1,16 +1,16 @@
/*
* Copyright (c) 2011 German Laullon
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -20,6 +20,8 @@
* THE SOFTWARE.
*/
+#define is_iOS_7 [[UIDevice currentDevice].systemVersion hasPrefix:@"7"]
+
#import "GLTapLabel.h"
@implementation GLTapLabel
@@ -32,7 +34,7 @@ -(void)drawTextInRect:(CGRect)rect
UIColor *origColor = [self textColor];
[origColor set];
if(!hotFont){
- hotFont = [UIFont fontWithName:[NSString stringWithFormat:@"%@-Bold",self.font.fontName] size:self.font.pointSize];
+ hotFont = [UIFont fontWithName:[NSString stringWithFormat:@"Helvetica-Bold"] size:self.font.pointSize];
}
if(!hotZones){
@@ -43,7 +45,21 @@ -(void)drawTextInRect:(CGRect)rect
[hotWords removeAllObjects];
}
- CGSize space = [@" " sizeWithFont:self.font constrainedToSize:rect.size lineBreakMode:self.lineBreakMode];
+ CGSize space = CGSizeZero;
+
+ if (is_iOS_7)
+ {
+ space = [@" " boundingRectWithSize:rect.size
+ options:NSStringDrawingUsesLineFragmentOrigin
+ attributes:@{NSFontAttributeName:self.font}
+ context:nil].size;
+ }
+ else
+ {
+ space = [@" " sizeWithFont:self.font constrainedToSize:rect.size lineBreakMode:self.lineBreakMode];
+ }
+
+
__block CGPoint drawPoint = CGPointMake(0,0);
NSString *read;
NSScanner *s = [NSScanner scannerWithString:self.text];
@@ -55,19 +71,42 @@ -(void)drawTextInRect:(CGRect)rect
// this is just to avoid ARC complications. We could just as easily make it __strong but then it won't work with non-ARC builds.
NSString* origWord = word;
NSString* newWord = word;
- CGSize s = [newWord sizeWithFont:self.font];
+ CGSize s = CGSizeZero;
+ if (is_iOS_7)
+ {
+ s = [newWord sizeWithAttributes:@{NSFontAttributeName:self.font}];
+ }
+ else
+ {
+ s = [newWord sizeWithFont:self.font];
+ }
NSString *cutWord = @"";
int c = [word length]-1;
while (s.width > rect.size.width) {
cutWord = [origWord substringFromIndex:c];
newWord = [origWord substringToIndex:c];
- s = [newWord sizeWithFont:self.font];
+ if (is_iOS_7)
+ {
+ s = [newWord sizeWithAttributes:@{NSFontAttributeName:self.font}];
+ }
+ else
+ {
+ s = [newWord sizeWithFont:self.font];
+ }
+
c -= 1;
if (s.width <= rect.size.width)
{
[words addObject:newWord];
origWord = cutWord;
- s = [origWord sizeWithFont:self.font];
+ if (is_iOS_7)
+ {
+ s = [newWord sizeWithAttributes:@{NSFontAttributeName:self.font}];
+ }
+ else
+ {
+ s = [newWord sizeWithFont:self.font];
+ }
c = [origWord length]-1;
}
}
@@ -77,7 +116,15 @@ -(void)drawTextInRect:(CGRect)rect
[words enumerateObjectsUsingBlock:^(NSString *word, NSUInteger idx, BOOL *stop) {
BOOL hot = [word hasPrefix:@"#"] || [word hasPrefix:@"@"];
UIFont *f= hot ? hotFont : self.font;
- CGSize s = [word sizeWithFont:f];
+ CGSize s = CGSizeZero;
+ if (is_iOS_7)
+ {
+ s = [word sizeWithAttributes:@{NSFontAttributeName:f}];
+ }
+ else
+ {
+ s = [word sizeWithFont:f];
+ }
if(drawPoint.x + s.width > rect.size.width) {
drawPoint = CGPointMake(0, drawPoint.y + s.height);
}
@@ -86,7 +133,16 @@ -(void)drawTextInRect:(CGRect)rect
[hotWords addObject:word];
[linkColor set];
}
- [word drawAtPoint:drawPoint withFont:f];
+ if (is_iOS_7)
+ {
+ [word drawAtPoint:drawPoint withAttributes:@{NSFontAttributeName:f}];
+ }
+ else
+ {
+ [word drawAtPoint:drawPoint withFont:f];
+
+ }
+
[origColor set];
drawPoint = CGPointMake(drawPoint.x + s.width + space.width, drawPoint.y);
@@ -96,11 +152,31 @@ -(void)drawTextInRect:(CGRect)rect
for(int idx=0;idx rect.size.width) {
drawPoint = CGPointMake(0, drawPoint.y + s.height);
}
- [word drawAtPoint:drawPoint withFont:self.font];
+
+ if(drawPoint.x + s.width > rect.size.width) {
+ drawPoint = CGPointMake(0, drawPoint.y + s.height);
+ }
+ if (is_iOS_7)
+ {
+ [word drawAtPoint:drawPoint withAttributes:@{NSFontAttributeName:self.font}];
+ }
+ else
+ {
+ [word drawAtPoint:drawPoint withFont:self.font];
+
+ }
drawPoint = CGPointMake(drawPoint.x + s.width, drawPoint.y);
}
}
@@ -110,7 +186,7 @@ -(void)drawTextInRect:(CGRect)rect
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = event.allTouches.anyObject;
- CGPoint point = [touch locationInView:self];
+ CGPoint point = [touch locationInView:self];
[hotZones enumerateObjectsUsingBlock:^(NSValue *obj, NSUInteger idx, BOOL *stop) {
CGRect hotzone = [obj CGRectValue];
if (CGRectContainsPoint(hotzone, point)) {
@@ -123,3 +199,4 @@ -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
}
@end
+