• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How do I use a NSTextBlock in an attributed string?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do I use a NSTextBlock in an attributed string?


  • Subject: How do I use a NSTextBlock in an attributed string?
  • From: Daryle Walker <email@hidden>
  • Date: Wed, 08 Mar 2017 16:17:39 -0500

I tried:

>             // Set the paragraph formatting for the body...
>             let bodyAdvancement = bodyFont.maximumAdvancement
>             let bodyIndent = max(bodyAdvancement.width, bodyAdvancement.height) / 2.0
>             let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() as! NSMutableParagraphStyle
>             bodyParagraphStyle.headIndent = bodyIndent
>             bodyParagraphStyle.lineBreakMode = .byWordWrapping
>
>             // ...and separator
>             let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() as! NSMutableParagraphStyle
>             let separatorTextBlock = NSTextBlock()
>             separatorParagraphStyle.textBlocks.append(separatorTextBlock)
>
>             // Set the body, but add a line for the initial separator
>             let richSeparator = NSMutableAttributedString(string: " \n", attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: separatorParagraphStyle])
>             let richBody = NSMutableAttributedString(string: body, attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: bodyParagraphStyle])
>             result.append(richSeparator)
>             result.append(richBody)

What I wanted: the separator line surrounded by a block.
What I got: the separator and the body all surrounded by a block.

I originally had the separator and body in a single string, and used a range to influence just the separator. This got the same result. I thought treating the separator and body in separate strings first wouldn’t infect the body with the text block, but it (illogically) does!

How do I end the influence of a block? Put -1 entries in the text-block array?

—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How do I use a NSTextBlock in an attributed string?
      • From: Daryle Walker <email@hidden>
  • Prev by Date: Re: needsDisplay and subviews
  • Next by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Previous by thread: Re: needsDisplay and subviews
  • Next by thread: Re: How do I use a NSTextBlock in an attributed string?
  • Index(es):
    • Date
    • Thread