nsattributedstring

Localising a UILabel with attributed string from a Storyboard

佐手、 提交于 2021-02-18 20:39:51
问题 I have a UILabel with text set as "attributed" in a storyboard. When I generate the Main.strings file for translating into a different language the text for this label does not appear. I tried to add manually an entry into the Main.strings file by copying the object id. I tried setting the "text" property and the "attributedText" property but when I run the app the translated string is not used. So, how do I localise an UILabel set as "attributed" on a storyboard? 回答1: I ended up solving this

Misaligned NSAttributedString in macOS NSStatusItem's button

陌路散爱 提交于 2021-02-11 15:05:01
问题 I would like to display a two-line NSAttributedString as the button title of the NSStatusItem of my macOS app. However, it seems to move the text up a few pixels and, thus, cut it off. This problem did not occur before macOS Big Sur. Workaround With some effort I managed to generate an NSImage of the text and use it as the button's image. Question Is there any way to position the NSAttributedString correctly without using an image? 来源: https://stackoverflow.com/questions/65167179/misaligned

Translate attributed string

纵然是瞬间 提交于 2021-02-07 11:36:30
问题 I have a UILabel with an attributed string. Here is a printscreen of it: Now, I have to translate this attributed string to english and italian. I am searching for a way to do this. Can I build this attributed string in code part by part? I have only found a solution where the whole string is set and then the attributes are set by range. But when I translate the string, I don't know the range anymore, because the words are longer or smaller. 回答1: Another option is to create localized .rtf

Nsattributedstring with different NSMutableParagraphStyle

六眼飞鱼酱① 提交于 2021-02-06 13:54:10
问题 I have 1 attributed string with multiple paragraph. I had given the FirstLineHeadIndent = 2.12. Now I want to give the FirstLineHeadIndent=0 to 1st paragraph and FirstLineHeadIndent=2 to 2nd paragraph in the attributed string. If I set the property like NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing =Line_space; paragraphStyle.firstLineHeadIndent =2; paragraphStyle.headIndent =margin_space; paragraphStyle.tailIndent =-margin_space;

Nsattributedstring with different NSMutableParagraphStyle

我怕爱的太早我们不能终老 提交于 2021-02-06 13:54:07
问题 I have 1 attributed string with multiple paragraph. I had given the FirstLineHeadIndent = 2.12. Now I want to give the FirstLineHeadIndent=0 to 1st paragraph and FirstLineHeadIndent=2 to 2nd paragraph in the attributed string. If I set the property like NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing =Line_space; paragraphStyle.firstLineHeadIndent =2; paragraphStyle.headIndent =margin_space; paragraphStyle.tailIndent =-margin_space;

Nsattributedstring with different NSMutableParagraphStyle

笑着哭i 提交于 2021-02-06 13:50:25
问题 I have 1 attributed string with multiple paragraph. I had given the FirstLineHeadIndent = 2.12. Now I want to give the FirstLineHeadIndent=0 to 1st paragraph and FirstLineHeadIndent=2 to 2nd paragraph in the attributed string. If I set the property like NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing =Line_space; paragraphStyle.firstLineHeadIndent =2; paragraphStyle.headIndent =margin_space; paragraphStyle.tailIndent =-margin_space;

NSMenuItem with attributedTitle containing an NSFont object draws the title with baseline shift

最后都变了- 提交于 2021-01-27 19:31:06
问题 I'm tying to create an NSPopUpButton with the list of fonts available in the system. Seemed pretty obvious task but I've failed. I guess, I'm missing something so obvious that I've completely forgot about it. The code is pretty straight: let button = NSPopUpButton() button.menu = NSMenu() NSFontManager.shared.availableFonts.forEach { fontNameString in let item = NSMenuItem() let font = NSFont(name: fontNameString, size: 14)! let attrs: [NSAttributedString.Key: Any] = [.font: font] item

NSString: strip out <b></b> and make an attributed string with color for that segment?

风流意气都作罢 提交于 2021-01-02 06:13:49
问题 Say if I have a string: This is a < b >simple < /b > string. I need to get rid of the < b >, (sorry there is no space between b and angle bracket, for some reason the preview does not show it), also make the word 'simple' to be bold, my thought was: replace the angle brackets and br with empty space make the 'simple' segment to have attributes The problem is once the tags are removed, I still need to know the word's location, do I first remember the location of 'simple', after removal, the

NSString: strip out <b></b> and make an attributed string with color for that segment?

一个人想着一个人 提交于 2021-01-02 06:13:39
问题 Say if I have a string: This is a < b >simple < /b > string. I need to get rid of the < b >, (sorry there is no space between b and angle bracket, for some reason the preview does not show it), also make the word 'simple' to be bold, my thought was: replace the angle brackets and br with empty space make the 'simple' segment to have attributes The problem is once the tags are removed, I still need to know the word's location, do I first remember the location of 'simple', after removal, the

NSString: strip out <b></b> and make an attributed string with color for that segment?

痴心易碎 提交于 2021-01-02 06:13:12
问题 Say if I have a string: This is a < b >simple < /b > string. I need to get rid of the < b >, (sorry there is no space between b and angle bracket, for some reason the preview does not show it), also make the word 'simple' to be bold, my thought was: replace the angle brackets and br with empty space make the 'simple' segment to have attributes The problem is once the tags are removed, I still need to know the word's location, do I first remember the location of 'simple', after removal, the