I'd like to slightly modify the y position of a character in an NSAttributedString. I know I can subscript (or superscript) using the attribute dictionary:
#{(id)kCTSuperscriptAttributeName: #(-1)}
Unfortunately the shift caused by this is too large in my case. I'm looking for an option to adjust the baseline in 1-point steps.
The attributed string will be displayed in a UIButton using -setAttributedTitle:forState:.
As of iOS 7 the NSBaselineOffsetAttributeName attribute has been added.
Yes you can... but only if you draw the text yourself like I am doing it in my DTCoreText open source project.
See line 924ff in DTCoreTextLayoutFrame.m here: https://github.com/Cocoanetics/DTCoreText/blob/master/Core/Source/DTCoreTextLayoutFrame.m
Unfortunately that's the ONLY way I know how to. UIKit does not give you this option.
Related
I'm new to coding and am stuck on formatting what I want to write. I need it formatted with bullet points and spaces. The easiest would be to just screenshot the page but I'd rather be able to change the words if necessary in case of changes later. Below is an example of what a protocol page looks like. That's what I need. Not a big run-on sentence.
How might I be able to accomplish this in Swift?
Here's an example
You have a few options:
• You can use a font symbol, like this: • (or an Emoji) inline with text.
• Use a customized webview to show stylized content.
• Render each line and custom bullet in Quartz.
You could also use the Unicode code point for the bullet character in your string.
myLabel.text = #"\u2022 This is a list item!";
Format UILabel with bullet points?
For long, complicated, pieces of text, you can use HTML and a WKWebView or instead use NSLayoutManager (which may be a bit complicated if you're just getting started), as described in the Text Layout Programming Guide.
I am using PDFKitten code. I have fixed all the issues regarding parsing of CMap, /Differences in that.
I have a pdf with TrueType and Type1 fonts.
I have parsed its differences and widths array.
However whenever I try to select or search text highlight is shown on the wrong position. What can be the problem?
I have applied MediaBox transform to drawing rect. It worked for some other pdfs but its not working for this. What more I have to do to solve this problem?
I have checked link for similar issue but solution is not working.
Thanks.
Adding the screenshot :
It turns out the glyph for particular unicode was not identified correctly. It is the bug in PDFKitten.
Resolved it by adding Glyph model by keeping it's width.
While calculating width instead of Mapping back to glyph I use glyph from model to get the width from the font.
I need to add a long string to a UiTextView/UiLabel or any UI Element. Parts of this string are of different colors. Also, i need to find out what will be the height of this element after setting this attributed string on it, given i hcan work out a fixed width. I know i can use boundingRectWithSize:, but how do i create dictionary, as there are more than one NSForegroundColorAttributeName values. Please help. Thanks in advance.
I have an iOS app which uses fixed width font label extensively.
After changing to the iOS 7 sdk and build target 6.1, all the label automagically replace occurences of three punctuation marks with an ellipsis character. This breaks a lot of stuff and looks weird, since the ellipsis character is not present in the font I use, and iOS sees fit to use one from a different font.
How do I stop this behaviour?
This is a ligature, and iOS seems to replace them automatically (like fl becomes fl). Seems like there are some options to disable them, see this question: Adjoining "f" and "l" characters
Alternative number three: insert a zero-width space (U+200B) between the dots.
(Posted as an answer per request of the OP)
One way around this is to replace the ASCII periods with a unicode 2024 character ("ONE DOT LEADER"). It looks exactly like a period but should not get converted automatically.
What you could do if this is widespread is to change all your UILabels to a subclass, MyLabel, and intercept messages to set the text, look for three dots, and if found change them to the unicode character above.
Yeah, this is a big PITA but I know of no other workaround.
EDIT
Another idea - find an open source UILabel (there must be at least one) and use it.
Another alternative : the ellipsis is a true character of its own. Why don't you try to add it yourself in your font (with Fontlab, FontForge or Glyphs) at the same width than the other characters?
Is that possible?
If not with CATextLAyer, then how can I do that?
You can use NSMutableAttributedString in CATextLayer. You can specify different attributes like color, font to different parts of string.
The solution was to break the word to letters and combine it back with 3 different text layers.
I will try to post the function i have build for others who needs it.