nsparagraphstyle

NSParagraphStyle defaultParagraphStyle not having effect

大兔子大兔子 提交于 2020-01-04 09:29:08
问题 Trying to set the paragraph styles for an NSTextView. Am I doing something wrong here, or putting the code in the wrong place perhaps..? I have this code in the subclass of my NSTextView. This does not affect my text view in any way: class EditorTextView: NSTextView { override func drawRect(dirtyRect: NSRect) { super.drawRect(dirtyRect) // to do } override func awakeFromNib() { var parastyle:NSMutableParagraphStyle = NSMutableParagraphStyle() parastyle.lineSpacing = 20 self

Draw a line inside a UITextView - NSAttributedString

有些话、适合烂在心里 提交于 2020-01-01 05:09:49
问题 I wish to draw a customizable line inside a UITextView consisting of some text (using NSAttributedString ) Here's what I tried NSString *unicodeStr = [NSString stringWithFormat:@"%C%C%C", 0x00A0, 0x0009, 0x00A0]; //nbsp, tab, nbsp NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:unicodeStr]; NSRange strRange = NSMakeRange(0, str.length); NSMutableParagraphStyle *const tabStyle = [[NSMutableParagraphStyle alloc] init]; tabStyle.headIndent = 16; //padding on

How can I add different line spacing for different parts of NSAttributedString?

若如初见. 提交于 2019-12-23 23:57:54
问题 I want to have a single NSAttributedString contain multiple messages. If a single message has a long text and it wraps around, I want to have a line spacing of, say, 5. Because I have a single NSAttributedString contain multiple messages, I want to have a bigger line spacing between each message; let's say 20. What I want The 'I see' is one message. The 'I'd think it'd be both...' is one message, although it wraps down to two lines and 'Like a one way chat' is one message. Notice how the line

How to set alignment for WKInterface Label using setAttributedText

﹥>﹥吖頭↗ 提交于 2019-12-22 10:48:14
问题 I'm trying to set alignment for WKInterfaceLabel using setAttributedText function. Here is my code: var paragraphStyle = NSParagraphStyle.defaultParagraphStyle() paragraphStyle.alignment = NSTextAlignment.Center var attributedDictonary = [NSForegroundColorAttributeName:UIColor.greenColor(), NSParagraphStyleAttributeName:paragraphStyle] var attributeString = NSAttributedString(string: "TextAttributed", attributes: attributedDictonary) self.titleLabel.setAttributedText(attributeString) But I

add hyphens on word break in a UILabel

做~自己de王妃 提交于 2019-12-17 15:44:31
问题 How do I set a UILabel lineBreakMode to break words and add hyphens to broken words? a label with a broken wo- rd should look like this 回答1: Elaborating on Matt's answer here: https://stackoverflow.com/a/16502598/196358 it can be done using NSAttributedString and NSParagraphStyle. See below: NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.hyphenationFactor = 1.0f; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]

lineSpacing property inside UILabel doesn't work as expected

守給你的承諾、 提交于 2019-12-12 00:33:12
问题 I am trying to create a custom UILabel class which will allow me to increase the line spacing on a UILabel. I know you can do this in IB with an attributed text string, however it doesn't work if you are using custom fonts. Here is my class code: import UIKit @IBDesignable class SpacingLabel: UILabel { @IBInspectable var lineSpacing: CGFloat = 10.0 override func awakeFromNib() { self.renderText() } override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() self.renderText

NSTextAlignmentCenter and NSTextAlignmentRight are the wrong way round in NSTextTab?

白昼怎懂夜的黑 提交于 2019-12-11 03:38:09
问题 Can anyone please check something for me... Just to make sure I'm not going mad! I created an NSMutableParagraphStyle with tabStops , but they weren't appearing where I was expecting: float width = self.myLabel.frame.size.width; self.tabStyle.tabStops = @[[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width - 50 options:nil], [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width options:nil]]; Then I created a convenience method to create an

How to set alignment for WKInterface Label using setAttributedText

别说谁变了你拦得住时间么 提交于 2019-12-06 00:58:12
I'm trying to set alignment for WKInterfaceLabel using setAttributedText function. Here is my code: var paragraphStyle = NSParagraphStyle.defaultParagraphStyle() paragraphStyle.alignment = NSTextAlignment.Center var attributedDictonary = [NSForegroundColorAttributeName:UIColor.greenColor(), NSParagraphStyleAttributeName:paragraphStyle] var attributeString = NSAttributedString(string: "TextAttributed", attributes: attributedDictonary) self.titleLabel.setAttributedText(attributeString) But I got a problem with this line: paragraphStyle.alignment = NSTextAlignment.Center I got error: Cannot

Draw a line inside a UITextView - NSAttributedString

a 夏天 提交于 2019-12-03 14:08:17
I wish to draw a customizable line inside a UITextView consisting of some text (using NSAttributedString ) Here's what I tried NSString *unicodeStr = [NSString stringWithFormat:@"%C%C%C", 0x00A0, 0x0009, 0x00A0]; //nbsp, tab, nbsp NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:unicodeStr]; NSRange strRange = NSMakeRange(0, str.length); NSMutableParagraphStyle *const tabStyle = [[NSMutableParagraphStyle alloc] init]; tabStyle.headIndent = 16; //padding on left and right edges tabStyle.firstLineHeadIndent = 16; tabStyle.tailIndent = -16; NSTextTab *listTab = [