Howto change from proportional to tabulated digits in menu items? - swift

I want to change from proportional to tabulated digits in menu items? It's possible?
Menu without tabulated digits

You need to use the monospaced font like this:
label.font = UIFont.monospacedDigitSystemFont(ofSize: 17, weight: UIFontWeightRegular)
Obviously you can specify whatever font size and weight you want (or get them from the current font descriptor).

You can set the attributedTitle property of a NSMenuItem and provide whatever custom alignment or formatting you want through an NSAttributedString
Good examples of how to do string alignment in an attributed string can be seen here:
Attributed Text Center Alignment
Here is an answer that shows how to add tab stops to an attributed string:
How do I add tab stops to an NSAttributedString
You can even create an attributed string from RTF or HTML:
Creating an NSAttributedString from HTML (or RTF)

Related

How to replace multiple glyphs in Swift NS/UITextView with a single icon

I'm struggling with this one for a while now. Its's about rendering markdown text in UI/NSTextView.
In the app "Bear" for Mac/iOS you can add a markdown link like [This is a link](https://...com) and it will hide the full URL and show a link symbol instead.
Here is a screenshot:
I know how to change colors using NSAttributedString and I know how to hide glyphs by overriding NSLayoutManagerDelegate.
There I override the shouldGenerateGlyphs func and change the properties of the glyphs to .null to hide them. Here I can also 'replace' a single glyph with something else by creating a CGGlyph(exactly: Int) and setting the glyph pointer to this in the same method where you can hide glyphs. But you can only replace a single glyph, not multiple.
While the above might work, it feels very hacky. I would need to hide all URL string glyphs, except the first, and turn that into a symbol somehow.
Is there any way to say something in the sense of mergeGlyphs(in range: NSRange, to glyph: CGGlyph) or to combine multiple glyphs to one or any other idea this could be achieved?

How to get the selected text's size(px) and font weight?

I am trying to get selected text's size(pixel) and font weight(pt) with AutoHotkey like HTML attributes. How do I do?
I have done some search on google and have found this:
Function: GetTextSize - Calculate text dimension
But every text have its own font-type and how this code works correctly for other font types?

iPhone SDK - UITextView text color split

I have a UITextView that I would like be be able to change the color for. But I would like to be able to change the color only after 50 characters. I can use UITextViewDelegate methods to count the characters, but I'm not sure how to change the color after that.
For instance, when I have a 100 character phrase within the UITextView, I would like the first 50 characters to be blue, and the last 50 characters to be red.
Is this possible? Any advice on how to achieve this?
Many thanks,
Brett
It is possible, but not via native UITextView or so
read more here:
http://www.cocoanetics.com/2011/01/rich-text-editing-on-ios/
http://www.scoop.it/t/iphone-and-ipad-development/p/104023127/rtlabel-rich-text-formatting-for-ios-using-html-like-markup-coding-for-mobile
http://iphoneincubator.com/blog/windows-views/display-rich-text-using-a-uiwebview
like #Nekto said
You can set only one color for all characters in one text view, using textColor property. If you want different colors in one sequence of characters, you can use, for example, UIWebView and html tags.

How to format different characters in a UILabel's string differently?

I have a UILabel with a dynamic string as the text property. If I always want the first word to be underlined, do I need to separate labels and then try to line them up correctly? Or could I subclass UILabel to have it do this?
Use a UIWebView and render the text as HTML.
I ended up using the textRectForBounds:limitedToNumberOfLines: to find the dynamic start point of the word (minus some x coordinate pixels), and then took away the first letter of the uilabel with stringByReplacingCharactersInRange:withString:, and then added another uilabel with the beginning letter of the original label, just with different font.

how to apply 2 text styles to a label in iphone

i have a tableview. in cell i am displaying some string data from xml.
in that string some italic tags and some normal tags r there.
but when i try to display the entire string it is displayed in normal text and not getting italic text.
i tried by taking 2 labels one with italic text and another with normal text and appending these 2 labels but i am getting entire string as italic.
how can we apply 2 styles in a label
Thanks in advance
Currently, the UILabel control does not support "rich text." You cannot have some text italic and some normal in the same UILabel.
Three20 has a label that supports this, however:
http://api.three20.info/interface_t_t_styled_text_label.php