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