Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #19 from bjhomer/pull-requests/align-tokens-vertic…

…ally-with-text-field

Align tokens on the last line vertically with the text field.
  • Loading branch information...
commit 88c6163ba3f3a38fb13edc7b31d221e622a91ecb 2 parents ee94d0f + 7abbe46
@jasarien authored
View
2  JSTokenField.xcodeproj/project.pbxproj
@@ -49,7 +49,7 @@
1A1A06B713FEE01C00CA6645 /* JSTokenButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTokenButton.h; sourceTree = "<group>"; };
1A1A06B813FEE01C00CA6645 /* JSTokenButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSTokenButton.m; sourceTree = "<group>"; };
1A1A06B913FEE01C00CA6645 /* JSTokenField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTokenField.h; sourceTree = "<group>"; };
- 1A1A06BA13FEE01C00CA6645 /* JSTokenField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSTokenField.m; sourceTree = "<group>"; };
+ 1A1A06BA13FEE01C00CA6645 /* JSTokenField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSTokenField.m; sourceTree = "<group>"; usesTabs = 1; };
1A1A06BD13FEE2D900CA6645 /* tokenHighlighted.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tokenHighlighted.png; sourceTree = "<group>"; };
1A1A06BE13FEE2D900CA6645 /* tokenHighlighted@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tokenHighlighted@2x.png"; sourceTree = "<group>"; };
1A1A06BF13FEE2D900CA6645 /* tokenNormal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tokenNormal.png; sourceTree = "<group>"; };
View
20 JSTokenField/JSTokenField.m
@@ -228,16 +228,22 @@ - (void)layoutSubviews
CGRect currentRect = CGRectZero;
[_label sizeToFit];
- [_label setFrame:CGRectMake(WIDTH_PADDING, HEIGHT_PADDING, [_label frame].size.width, [_label frame].size.height + 3)];
+ [_label setFrame:CGRectMake(WIDTH_PADDING, HEIGHT_PADDING, [_label frame].size.width, [_label frame].size.height + HEIGHT_PADDING)];
- currentRect.origin.x += _label.frame.size.width + _label.frame.origin.x + WIDTH_PADDING;
+ currentRect.origin.x = _label.frame.origin.x;
+ if (_label.frame.size.width > 0) {
+ currentRect.origin.x += _label.frame.size.width + WIDTH_PADDING;
+ }
+ NSMutableArray *lastLineTokens = [NSMutableArray array];
+
for (UIButton *token in _tokens)
{
CGRect frame = [token frame];
if ((currentRect.origin.x + frame.size.width) > self.frame.size.width)
{
+ [lastLineTokens removeAllObjects];
currentRect.origin = CGPointMake(WIDTH_PADDING, (currentRect.origin.y + frame.size.height + HEIGHT_PADDING));
}
@@ -250,6 +256,7 @@ - (void)layoutSubviews
{
[self addSubview:token];
}
+ [lastLineTokens addObject:token];
currentRect.origin.x += frame.size.width + WIDTH_PADDING;
currentRect.size = frame.size;
@@ -265,6 +272,7 @@ - (void)layoutSubviews
}
else
{
+ [lastLineTokens removeAllObjects];
textFieldFrame.size.width = self.frame.size.width;
textFieldFrame.origin = CGPointMake(WIDTH_PADDING * 2,
(currentRect.origin.y + currentRect.size.height + HEIGHT_PADDING));
@@ -275,6 +283,14 @@ - (void)layoutSubviews
CGRect selfFrame = [self frame];
selfFrame.size.height = textFieldFrame.origin.y + textFieldFrame.size.height + HEIGHT_PADDING;
+ CGFloat textFieldMidY = CGRectGetMidY(textFieldFrame);
+ for (UIButton *token in lastLineTokens) {
+ // Center the last line's tokens vertically with the text field
+ CGPoint tokenCenter = token.center;
+ tokenCenter.y = textFieldMidY;
+ token.center = tokenCenter;
+ }
+
[UIView animateWithDuration:0.3
animations:^{
[self setFrame:selfFrame];
Please sign in to comment.
Something went wrong with that request. Please try again.