83358

Can I adjust the baseline in an NSAttributedString without increasing the line height?

In the San Francisco font, brackets are a bit low if they surround numbers. An example from the app I'm making, using an NSAttributedString:

<img src=https://www.e-learn.cn/content/wangluowenzhang/"https://i.stack.imgur.com/Odc33.png" alt="example">

I'd like to increase the baseline for the brackets by a pixel or two, but when I do that using the NSBaselineOffsetAttributeName attribute, the line height is increased by two pixels as well. The text is inside a UITextView, and I really wouldn't like the line height to change. Is there anything I can do?

Answer1:

A possible way to do it is to force the maximum line height with NSParagraphAttributeName.

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setMaximumLineHeight:maxHeightWanted]; NSDictionary *parenthesisAttributes = @{NSParagraphStyleAttributeName:style, NSBaselineOffsetAttributeName:@(baselineWanted), NSFontAttributeName:sameFontWithBiggerPointSize};

Recommend

  • UITextView initial scroll position is not 0
  • Formatted text in UILabel on iPhone
  • Append NSAttributed text to UITextview
  • How to render HTML string in UITextview with different font styles but same font family
  • Can't set @IBInspectable computed property in UIView
  • Swift parse html table
  • How to define a generic method that returns an instance of the deriving class type?
  • How to find exact size for an arbitrary glyph in WPF?
  • y axis start from 10 rather than 0 in mschart using windows application
  • Chrome align-items: baseline for select and input elements
  • Bash: sort find results using part of a filename [duplicate]
  • Access each Pixel of AVFrame
  • C#: Decoding JPEG images with 12-bit precision using Silverlight FJCore library?
  • Putting text shadow on a UIButton text label
  • How to save a large fractal image with the least possible memory footprint?
  • OpenCV OpenNI calibrate kinect
  • TCPDF's getNumLines() is sometimes wrong
  • How to get a table cell value using jQuery
  • Updating one element of a bound Observable collection
  • How to remove all of a jQuery UI dialog when it is closed
  • Parenthesis() and SQL Query Performance
  • calculating number of bytes of each row in an image
  • Responsive Form on top of Responsive Image? - Bootstrap
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • Flex items with same property values are rendering in different sizes
  • Write output of for loop to multiple files
  • Plotting densities in R
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • chrome video src change not working
  • WPF Template Binding in ToggleButton UserControl
  • blade.php method outputting it's result to the form
  • Floated image with variable width and heading with background image
  • Can't delete or rename original file after resizing
  • D3 get axis values on zoom event
  • Converting a WriteableBitmap image ToArray in UWP
  • How to define and use opencv mat of user type
  • Magento Fatal error: Maximum execution error solution, on WAMP
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • How to set/get protobuf's extension field in Go?
  • How to show dropdown in excel using jrxml (jasper api)?