Skip to content


Fixed button textTitle frame based on title edge inset #96

wants to merge 1 commit into from

2 participants


No description provided.


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.


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
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/UIKit/TUIButton.m
9 lib/UIKit/TUIButton.m
@@ -198,10 +198,11 @@ - (void)drawRect:(CGRect)r
CGContextTranslateCTM(ctx, _titleEdgeInsets.left, _titleEdgeInsets.bottom);
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,
+ bounds.size.width - _titleEdgeInsets.left - _titleEdgeInsets.right,
+ bounds.size.height - - _titleEdgeInsets.bottom);
+ [_titleView drawRect:_titleView.bounds];
Something went wrong with that request. Please try again.