• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating a single Tab Stop in an NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a single Tab Stop in an NSTextView


  • Subject: Re: Creating a single Tab Stop in an NSTextView
  • From: Ian was here <email@hidden>
  • Date: Sun, 22 Jan 2006 11:01:48 -0800 (PST)

Thanks Patrick,


That did the trick! Following is the code that inserts
just a single tab stop in a text view. The reason for
this was to create a bullet list that was pre OS X
10.4 compatible.



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];

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




--- Patrick Meirmans <email@hidden> wrote:

> The following code works for me to insert a number
> tabstops, though I
> think it is more or less the same as what you do. I
> cut out some code
> where I programmatically set the number of tabs and
> their spacing, so
> there is the risk that I cut out a bit too much and
> the code will
> generate some errors, but you will get the general
> idea:
>
>      int i;
>      int numStops = 100;
>      int tabInterval = 80.0;
>      NSTextTab *tabStop;
>
>      NSMutableDictionary *attrs =
> [[NSMutableDictionary alloc] init];
> //attributes for attributed String of TextView
>      NSMutableParagraphStyle *paraStyle =
> [[NSMutableParagraphStyle
> alloc] init];
>
>      // This first clears all tab stops, then adds
> tab stops, at desired
> intervals...
>      [paraStyle setTabStops:[NSArray array]];
>      for (i = 1; i <= numStops; i++) {
>          tabStop = [[NSTextTab alloc]
> initWithType:NSLeftTabStopType
> location: tabInterval * i];
>          [paraStyle addTabStop:tabStop];
>          [tabStop release];
>      }
>      [attrs setObject:paraStyle
> forKey:NSParagraphStyleAttributeName];
>      [paraStyle release];
>
>      [[dataTextView textStorage] addAttributes:attrs
>
> range:NSMakeRange(0, [[[myTextView textStorage]
> string] length])];
>      [attrs release];
>
>
> On 17 Jan, 2006, at 11:46, Ian was here wrote:
>
> > I'm trying to reset the position of the first tab
> stop
> > within my text view. I would like it to be at
> position
> > 48. For some reason the following code doesn't
> seem to
> > do the trick. Has anyone else done something
> similar
> > to this?
> >
> >
> >
> > NSMutableParagraphStyle	    *theParagraphStyle =
> > [[NSMutableParagraphStyle alloc] init];
> > NSTextTab			    *textTab = [[NSTextTab alloc]
> > initWithType:NSLeftTabStopType location:48.0];
> >
> > NSArray	         *tabStop = [[NSArray alloc]
> > initWithObjects:textTab, nil];
> >
> >
> > [theParagraphStyle setTabStops:tabStop];
> > [textView
> setDefaultParagraphStyle:theParagraphStyle];
> >
> > [tabStop release];
> > [textTab release];
> > [theParagraphStyle release];
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >  _______________________________________________
> > Do not post admin requests to the list. They will
> be ignored.
> > Cocoa-dev mailing list
> (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> > email@hidden
> >
> > This email sent to email@hidden
> >
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Creating a single Tab Stop in an NSTextView (From: Patrick Meirmans <email@hidden>)

  • Prev by Date: Re: Resizing an image
  • Next by Date: NSWorkspace ... launchApplication
  • Previous by thread: Re: Creating a single Tab Stop in an NSTextView
  • Next by thread: Code moved to plugin, undefined symbol
  • Index(es):
    • Date
    • Thread