PDA

View Full Version : setDefaultParagraphStyle not working with NSTextView




beppeabresh
Jan 17, 2009, 06:43 AM
Hello,

I'm trying to increase line spacing of an editable NStextView with richtext, after searching documentation, specially the TextEdit's source, I've tried this two approaches:

1. Using setDefaultParagraphStyle:

- (id)initWithCoder: (NSCoder *)coder {
if (self = [super initWithCoder:coder]) {

// Initialization code here.

NSMutableParagraphStyle *menuStyle = [[NSMutableParagraphStyle alloc] init];
[menuStyle setMaximumLineHeight:100];
[menuStyle setLineSpacing:22];

[impostaDescrizioneAgg setDefaultParagraphStyle:menuStyle];

}

return self;
}

Wich has no effect on my "impostaDescrizioneAgg" object, an IB-created nstextview that IBOutlet's inside the class i'm initializing right there.

2. After that i've just found some code online that someone said it was working, i've pasted and the result was nothing (it should add a TAB to the textview):

NSMutableDictionary *attsDict =
[[NSMutableDictionary alloc] init];
NSMutableParagraphStyle *paraStyle =
[[NSMutableParagraphStyle alloc] init];
NSTextTab *tabStop = [[NSTextTab alloc]
initWithType:NSLeftTabStopType location:100.0];


[paraStyle setTabStops:[NSArray array]];
[paraStyle addTabStop:tabStop];
[tabStop release];

[attsDict setObject:paraStyle
forKey:NSParagraphStyleAttributeName];
[paraStyle release];

[[impostaDescrizioneAgg textStorage] addAttributes:attsDict range:NSMakeRange(
0, [[impostaDescrizioneAgg string] length] )];

[attsDict release];


So, if anyone knows how to handle this and how to make my textview receive the paragraph changes, it will be really appreciated.

Thank you in advance.