Skip to content

Commit

Permalink
fixed issue with setting autoresizingMask on UIButtons with only text…
Browse files Browse the repository at this point in the history
… in Popover with title.

For some reason the buttons frames were being resized past the Popover bounds causing issues with text alignment. Now all UIButtons are resized to the full width of the Popover view and text alignment is handled by the UIButton.

Signed-off-by: Jared Allen <jared@redcact.us>
  • Loading branch information
jallen committed Jan 31, 2013
1 parent bd8de55 commit bfe1db9
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions PopoverView/PopoverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,10 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withViewArray:(NSArray

totalHeight = 0;

//Now we actually change the frame element for each subview, and center the views horizontally.
//Now we actually change the frame element for each subview to make sure all views are the full width.
for (UIView *view in viewArray) {
if ([view autoresizingMask] == UIViewAutoresizingFlexibleWidth) {
//Now make sure all flexible views are the full width
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, totalWidth, view.frame.size.height);
} else {
//If the view is not flexible width, then we position it centered in the view
//without stretching it.
view.frame = CGRectMake(floorf(CGRectGetMinX(boxFrame) + totalWidth*0.5f - view.frame.size.width*0.5f), view.frame.origin.y, view.frame.size.width, view.frame.size.height);
}

view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, totalWidth, view.frame.size.height);

//and if dividers are enabled, we record their position for the drawing methods
if (kShowDividersBetweenViews && i != viewArray.count-1) {
CGRect dividerRect = CGRectMake(view.frame.origin.x, floorf(view.frame.origin.y + view.frame.size.height + kBoxPadding*0.5f), view.frame.size.width, 0.5f);
Expand Down Expand Up @@ -316,13 +309,10 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t
float padding = (i == viewArray.count-1) ? 0.f : kBoxPadding;

totalHeight += view.frame.size.height + padding;

if (view.frame.size.width > totalWidth) {
totalWidth = view.frame.size.width;
}

[container addSubview:view];

totalWidth = MAX(totalWidth, view.frame.size.width);

[container addSubview:view];

i++;
}

Expand All @@ -332,17 +322,11 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t
}

i = 0;

for (UIView *view in viewArray) {
if ([view autoresizingMask] == UIViewAutoresizingFlexibleWidth) {
//Now make sure all flexible views are the full width
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, totalWidth, view.frame.size.height);
} else {
//If the view is not flexible width, then we position it centered in the view
//without stretching it.
view.frame = CGRectMake(floorf(CGRectGetMinX(boxFrame) + totalWidth*0.5f - view.frame.size.width*0.5f), view.frame.origin.y, view.frame.size.width, view.frame.size.height);
}


//Now we actually change the frame element for each subview to make sure all views are the full width.
for (UIView *view in viewArray) {
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, totalWidth, view.frame.size.height);

//and if dividers are enabled, we record their position for the drawing methods
if (kShowDividersBetweenViews && i != viewArray.count-1) {
CGRect dividerRect = CGRectMake(view.frame.origin.x, floorf(view.frame.origin.y + view.frame.size.height + kBoxPadding*0.5f), view.frame.size.width, 0.5f);
Expand Down Expand Up @@ -490,7 +474,6 @@ - (UIButton *)_makeButtonWithString:(NSString *)string

CGSize textSize = [string sizeWithFont:font];
UIButton *textButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textSize.width, textSize.height)];
textButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
textButton.backgroundColor = [UIColor clearColor];
textButton.titleLabel.font = font;
textButton.titleLabel.textColor = kTextColor;
Expand Down

0 comments on commit bfe1db9

Please sign in to comment.