Skip to content

Commit

Permalink
Merge pull request #20 from Krelborn/develop
Browse files Browse the repository at this point in the history
Develop merged to Master. Merge for 1.0.1 bugfix release.
  • Loading branch information
Krelborn committed May 26, 2015
2 parents d34e2f7 + dadf3af commit 793ac34
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions KILabel.podspec
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|

s.name = "KILabel"
s.version = "1.0.0"
s.version = "1.0.1"
s.summary = "Replacement for UILabel for iOS 7 and 8 that provides automatic detection of links such as URLs, twitter style usernames and hashtags."

s.description = <<-DESC
Expand All @@ -27,7 +27,7 @@ Pod::Spec.new do |s|

s.platform = :ios, "7.0"

s.source = { :git => "https://github.com/Krelborn/KILabel.git", :tag => "1.0.0" }
s.source = { :git => "https://github.com/Krelborn/KILabel.git", :tag => "1.0.1" }

s.source_files = "KILabel/Source/**/*.{h,m}"
public_header_files = "KILabel/Source/**/*.h"
Expand Down
52 changes: 26 additions & 26 deletions KILabel/Source/KILabel.m
Expand Up @@ -152,9 +152,7 @@ - (NSDictionary *)linkAtPoint:(CGPoint)location
}

// Work out the offset of the text in the view
CGPoint textOffset;
NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer];
textOffset = [self calcTextOffsetForGlyphRange:glyphRange];
CGPoint textOffset = [self calcGlyphsPositionInView];

// Get the touch location and use text offset to convert to text cotainer coords
location.x -= textOffset.x;
Expand Down Expand Up @@ -543,23 +541,23 @@ - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)num
_textContainer.maximumNumberOfLines = numberOfLines;

// Measure the text with the new state
CGRect textBounds;
@try
{
NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer];
textBounds = [_layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:_textContainer];

// Position the bounds and round up the size for good measure
textBounds.origin = bounds.origin;
textBounds.size.width = ceilf(textBounds.size.width);
textBounds.size.height = ceilf(textBounds.size.height);
}
@finally
CGRect textBounds = [_layoutManager usedRectForTextContainer:_textContainer];

// Position the bounds and round up the size for good measure
textBounds.origin = bounds.origin;
textBounds.size.width = ceil(textBounds.size.width);
textBounds.size.height = ceil(textBounds.size.height);

if (textBounds.size.height < bounds.size.height)
{
// Restore the old container state before we exit under any circumstances
_textContainer.size = savedTextContainerSize;
_textContainer.maximumNumberOfLines = savedTextContainerNumberOfLines;
// Take verical alignment into account
CGFloat offsetY = (bounds.size.height - textBounds.size.height) / 2.0;
textBounds.origin.y += offsetY;
}

// Restore the old container state before we exit under any circumstances
_textContainer.size = savedTextContainerSize;
_textContainer.maximumNumberOfLines = savedTextContainerNumberOfLines;

return textBounds;
}
Expand All @@ -571,24 +569,26 @@ - (void)drawTextInRect:(CGRect)rect
// [super drawTextInRect:rect];

// Calculate the offset of the text in the view
CGPoint textOffset;
NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer];
textOffset = [self calcTextOffsetForGlyphRange:glyphRange];
CGPoint glyphsPosition = [self calcGlyphsPositionInView];

// Drawing code
[_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:textOffset];
[_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:textOffset];
[_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:glyphsPosition];
[_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:glyphsPosition];
}

// Returns the XY offset of the range of glyphs from the view's origin
- (CGPoint)calcTextOffsetForGlyphRange:(NSRange)glyphRange
- (CGPoint)calcGlyphsPositionInView
{
CGPoint textOffset = CGPointZero;

CGRect textBounds = [_layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:_textContainer];
CGFloat paddingHeight = (self.bounds.size.height - textBounds.size.height) / 2.0f;
if (paddingHeight > 0)
CGRect textBounds = [_layoutManager usedRectForTextContainer:_textContainer];
textBounds.size.width = ceil(textBounds.size.width);
textBounds.size.height = ceil(textBounds.size.height);

if (textBounds.size.height < self.bounds.size.height)
{
CGFloat paddingHeight = (self.bounds.size.height - textBounds.size.height) / 2.0;
textOffset.y = paddingHeight;
}

Expand Down
12 changes: 6 additions & 6 deletions KILabelDemo/KILabelDemo/KIViewController.m
Expand Up @@ -147,11 +147,11 @@ - (IBAction)toggleDetectURLs:(UISwitch *)sender
{
if (sender.isOn)
{
self.label.linkDetectionTypes |= KILinkTypeURL;
self.label.linkDetectionTypes |= KILinkTypeOptionURL;
}
else
{
self.label.linkDetectionTypes ^= KILinkTypeURL;
self.label.linkDetectionTypes ^= KILinkTypeOptionURL;
}
}

Expand All @@ -164,11 +164,11 @@ - (IBAction)toggleDetectUsernames:(UISwitch *)sender
{
if (sender.isOn)
{
self.label.linkDetectionTypes |= KILinkTypeUserHandle;
self.label.linkDetectionTypes |= KILinkTypeOptionUserHandle;
}
else
{
self.label.linkDetectionTypes ^= KILinkTypeUserHandle;
self.label.linkDetectionTypes ^= KILinkTypeOptionUserHandle;
}
}

Expand All @@ -181,11 +181,11 @@ - (IBAction)toggleDetectHashtags:(UISwitch *)sender
{
if (sender.isOn)
{
self.label.linkDetectionTypes |= KILinkTypeHashtag;
self.label.linkDetectionTypes |= KILinkTypeOptionHashtag;
}
else
{
self.label.linkDetectionTypes ^= KILinkTypeHashtag;
self.label.linkDetectionTypes ^= KILinkTypeOptionHashtag;
}
}

Expand Down

0 comments on commit 793ac34

Please sign in to comment.