Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed button textTitle frame based on title edge inset #96

Open
wants to merge 1 commit into from

2 participants

@brutella

No description provided.

@avaidyam

How would I center the text horizontally, and vertically, and both, using edge insets? When I use an iOS category on UIButton (renamed to TUIButton) to do it, the centering is slightly off.

Use the textAlignment property of the TUILabel class, which is used by the TUIButton to draw the text.

Thanks!

Another question- how would I center the label to the right, halfway vertically? I can't get edge insets to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/UIKit/TUIButton.m
View
9 lib/UIKit/TUIButton.m
@@ -198,10 +198,11 @@ - (void)drawRect:(CGRect)r
CGContextTranslateCTM(ctx, _titleEdgeInsets.left, _titleEdgeInsets.bottom);
if(!key)
CGContextSetAlpha(ctx, 0.5);
- CGRect titleFrame = self.bounds;
- titleFrame.size.width -= (_titleEdgeInsets.left + _titleEdgeInsets.right);
- _titleView.frame = titleFrame;
- [_titleView drawRect:_titleView.bounds];
+ _titleView.frame = CGRectMake(_titleEdgeInsets.left,
+ _titleEdgeInsets.top,
+ bounds.size.width - _titleEdgeInsets.left - _titleEdgeInsets.right,
+ bounds.size.height - _titleEdgeInsets.top - _titleEdgeInsets.bottom);
+ [_titleView drawRect:_titleView.bounds];
CGContextRestoreGState(ctx);
}
Something went wrong with that request. Please try again.