Skip to content

Commit

Permalink
Corrections to show correct HeightLabel
Browse files Browse the repository at this point in the history
As seen in this pull request
Sumi-Interactive#103
  • Loading branch information
SantiBec committed Mar 23, 2016
1 parent 747e53d commit 2b3e0cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions SIAlertView/SIAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
@property (nonatomic, strong) UIColor *destructiveButtonColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property (nonatomic, assign) CGFloat cornerRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 2.0
@property (nonatomic, assign) CGFloat shadowRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 8.0
@property (nonatomic, assign) NSInteger maximumNumberOfLines NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 5

- (void)setDefaultButtonImage:(UIImage *)defaultButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (void)setCancelButtonImage:(UIImage *)cancelButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
Expand Down
19 changes: 8 additions & 11 deletions SIAlertView/SIAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define DEBUG_LAYOUT 0

#define MESSAGE_MIN_LINE_COUNT 3
#define MESSAGE_MAX_LINE_COUNT 5
#define GAP 10
#define CANCEL_BUTTON_PADDING_TOP 5
#define CONTENT_PADDING_LEFT 10
Expand Down Expand Up @@ -247,6 +246,7 @@ + (void)initialize
appearance.destructiveButtonColor = [UIColor whiteColor];
appearance.cornerRadius = 2;
appearance.shadowRadius = 8;
appearance.maximumNumberOfLines = 5;
}

- (id)init
Expand Down Expand Up @@ -839,20 +839,17 @@ - (CGFloat)heightForTitleLabel

- (CGFloat)heightForMessageLabel
{
CGFloat minHeight = MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight;
CGFloat minHeight = ceilf(MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight);
if (self.messageLabel) {
CGFloat maxHeight = MESSAGE_MAX_LINE_COUNT * self.messageLabel.font.lineHeight;
CGFloat maxHeight = ceilf(self.maximumNumberOfLines * self.messageLabel.font.lineHeight);

#ifdef __IPHONE_7_0
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = self.messageLabel.lineBreakMode;

NSDictionary *attributes = @{NSFontAttributeName:self.messageLabel.font,
NSParagraphStyleAttributeName: paragraphStyle.copy};

NSDictionary *attributes = @{
+ NSFontAttributeName:self.messageLabel.font,
+ };
// NSString class method: boundingRectWithSize:options:attributes:context is
// available only on ios7.0 sdk.
CGRect rect = [self.titleLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight)
CGRect rect = [self.messageLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
Expand Down Expand Up @@ -941,7 +938,7 @@ - (void)updateMessageLabel
self.messageLabel.backgroundColor = [UIColor clearColor];
self.messageLabel.font = self.messageFont;
self.messageLabel.textColor = self.messageColor;
self.messageLabel.numberOfLines = MESSAGE_MAX_LINE_COUNT;
self.messageLabel.numberOfLines = self.maximumNumberOfLines;
[self.containerView addSubview:self.messageLabel];
#if DEBUG_LAYOUT
self.messageLabel.backgroundColor = [UIColor redColor];
Expand Down

0 comments on commit 2b3e0cf

Please sign in to comment.