• 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: Automatically replacing part of text in a text label
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatically replacing part of text in a text label


  • Subject: Re: Automatically replacing part of text in a text label
  • From: Peter Zegelin <email@hidden>
  • Date: Wed, 18 Mar 2009 13:41:21 +1100


On 16/03/2009, at 5:20 PM, Peter Zegelin wrote:

OK - thanks everyone.

Just as I was about to wire things up in IB I realised that a subclass of NSTextField would be the best way. Turns out its a one liner in awakeFromNib.

- (void)awakeFromNib {

[self setStringValue:[[self stringValue] stringByReplacingOccurrencesOfString:@"<ApplicationName>" withString: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]]];
}



In the same vein I have two other bits where I would like to automatically replace text. The first is my 'Warranty Panel'. I am currently loading it into an NSTextView like so:


[warrantyTextField readRTFDFromFile:[[NSBundle mainBundle] pathForResource:@"LicenseAgreement" ofType:@"rtf"]];

Because it is rtf, I understand it is much more involved to change all occurrences of <ApplicationName>. Does anyone know of an example how this is done? I found a few things like OmniAppkit that have a Find and Replace Panel but they seem way too complicated for this.



The second area is some menus under the application menu - specifically About... Hide and Quit. The top level Menu seems to reflect the application name but the rest just show About NewApplication etc. Would the best way to change these automatically be to:

wire up the first menu to my app delegate
get all the items with - (NSArray *)itemArray on awakeFromNib
iterate over all items in this array replacing the string like with my NSTextField subclass above?


Thanks!

Peter



I have some text labels in a registration dialog that contain the application name eg

"xxx Demonstration"
"Thank you for purchasing xxx"

and so on.

I would like this registration dialog to be general enough that I can use it in multiple applications. Is there a simple way to replace the xxx with the actual application name at runtime? At the moment I'm thinking I'll have to wire every label up to my registration controller and do it in awakeFromNib, but I was hoping for something easier.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Automatically replacing part of text in a text label
      • From: Michael Ash <email@hidden>
References: 
 >Automatically replacing part of text in a text label (From: Peter Zegelin <email@hidden>)

  • Prev by Date: Re: "selector ... is passed a return code and caller specified in contextInfo" ?!?!
  • Next by Date: Re: cast to pointer from int of diff size & IODisplayCreateInfoDictionary
  • Previous by thread: Re: Automatically replacing part of text in a text label
  • Next by thread: Re: Automatically replacing part of text in a text label
  • Index(es):
    • Date
    • Thread