Skip to content

Commit 2d67885

Browse files
committed
Merge pull request Sumi-Interactive#75 from edwardmp/master
Fix for methods that are deprectated in iOS 7.0 SDK
2 parents 99a73ec + 4d05a3c commit 2d67885

2 files changed

Lines changed: 54 additions & 17 deletions

File tree

SIAlertView.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Pod::Spec.new do |s|
22
s.name = 'SIAlertView'
3-
s.version = '1.3'
3+
s.version = '1.3.1'
44
s.platform = :ios, '5.0'
55
s.license = 'MIT'
66
s.summary = 'An UIAlertView replacement.'
77
s.homepage = 'https://github.com/Sumi-Interactive/SIAlertView'
88
s.author = { 'Sumi Interactive' => '[email protected]' }
99
s.source = { :git => 'https://github.com/Sumi-Interactive/SIAlertView.git',
10-
:tag => '1.3' }
10+
:tag => '1.3.1' }
1111

1212
s.description = 'An UIAlertView replacement with block syntax and fancy transition styles.'
1313

SIAlertView/SIAlertView.m

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -798,18 +798,35 @@ - (CGFloat)preferredHeight
798798
- (CGFloat)heightForTitleLabel
799799
{
800800
if (self.titleLabel) {
801-
CGSize size = [self.title sizeWithFont:self.titleLabel.font
802-
minFontSize:
803-
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0
804-
self.titleLabel.font.pointSize * self.titleLabel.minimumScaleFactor
805-
#else
806-
self.titleLabel.minimumFontSize
807-
#endif
808-
actualFontSize:nil
809-
forWidth:CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2
810-
lineBreakMode:self.titleLabel.lineBreakMode];
811-
return size.height;
801+
#ifdef __IPHONE_7_0
802+
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
803+
paragraphStyle.lineBreakMode = self.titleLabel.lineBreakMode;
804+
805+
NSDictionary *attributes = @{NSFontAttributeName:self.titleLabel.font,
806+
NSParagraphStyleAttributeName: paragraphStyle.copy};
807+
808+
// NSString class method: boundingRectWithSize:options:attributes:context is
809+
// available only on ios7.0 sdk.
810+
CGRect rect = [self.titleLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, CGFLOAT_MAX)
811+
options:NSStringDrawingUsesLineFragmentOrigin
812+
attributes:attributes
813+
context:nil];
814+
return ceil(rect.size.height);
815+
#else
816+
CGSize size = [self.title sizeWithFont:self.titleLabel.font
817+
minFontSize:
818+
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0
819+
self.titleLabel.font.pointSize * self.titleLabel.minimumScaleFactor
820+
#else
821+
self.titleLabel.minimumFontSize
822+
#endif
823+
actualFontSize:nil
824+
forWidth:CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2
825+
lineBreakMode:self.titleLabel.lineBreakMode];
826+
return size.height;
827+
#endif
812828
}
829+
813830
return 0;
814831
}
815832

@@ -818,11 +835,31 @@ - (CGFloat)heightForMessageLabel
818835
CGFloat minHeight = MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight;
819836
if (self.messageLabel) {
820837
CGFloat maxHeight = MESSAGE_MAX_LINE_COUNT * self.messageLabel.font.lineHeight;
821-
CGSize size = [self.message sizeWithFont:self.messageLabel.font
822-
constrainedToSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight)
823-
lineBreakMode:self.messageLabel.lineBreakMode];
824-
return MAX(minHeight, size.height);
838+
839+
#ifdef __IPHONE_7_0
840+
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
841+
paragraphStyle.lineBreakMode = self.messageLabel.lineBreakMode;
842+
843+
NSDictionary *attributes = @{NSFontAttributeName:self.messageLabel.font,
844+
NSParagraphStyleAttributeName: paragraphStyle.copy};
845+
846+
// NSString class method: boundingRectWithSize:options:attributes:context is
847+
// available only on ios7.0 sdk.
848+
CGRect rect = [self.titleLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight)
849+
options:NSStringDrawingUsesLineFragmentOrigin
850+
attributes:attributes
851+
context:nil];
852+
853+
return MAX(minHeight, ceil(rect.size.height));
854+
#else
855+
CGSize size = [self.message sizeWithFont:self.messageLabel.font
856+
constrainedToSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight)
857+
lineBreakMode:self.messageLabel.lineBreakMode];
858+
859+
return MAX(minHeight, size.height);
860+
#endif
825861
}
862+
826863
return minHeight;
827864
}
828865

0 commit comments

Comments
 (0)