From 33dfc9db928275e0b8d2f62433839cb649a2734b Mon Sep 17 00:00:00 2001 From: Tucker Connelly Date: Fri, 10 Jun 2016 04:20:12 -0700 Subject: [PATCH] Vertically center iOS text if lineHeight is set Summary: First PR!! This fixes https://github.com/facebook/react-native/issues/2991 :) Closes https://github.com/facebook/react-native/pull/7603 Differential Revision: D3417257 fbshipit-source-id: 074d56c1dfc0a9ba713e59c804286fd915589eeb --- Libraries/Text/RCTShadowText.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index eced9cd0cd827e..72461db6e68b01 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -369,6 +369,14 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib } paragraphStyle.minimumLineHeight = lineHeight; paragraphStyle.maximumLineHeight = lineHeight; + + // vertically center text + CGFloat fontSize = _fontSize && !isnan(_fontSize) ? _fontSize : UIFont.systemFontSize; + fontSize *= fontSizeMultiplier; + + [attributedString addAttribute:NSBaselineOffsetAttributeName + value:@(lineHeight/2 - fontSize/2) + range:(NSRange){0, attributedString.length}]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:(NSRange){0, attributedString.length}];