Permalink
Browse files

Fixed button textTitle frame based on title edge inset

  • Loading branch information...
1 parent 03c9552 commit 6d4a09097eff95464adb39064cbf5b9d0dc9f600 @brutella committed Jan 18, 2012
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);
}

4 comments on commit 6d4a090

@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.

@brutella
Owner

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

@avaidyam

Thanks!

@avaidyam

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

Please sign in to comment.