Re: NSAttributedString with embedded image
Re: NSAttributedString with embedded image
- Subject: Re: NSAttributedString with embedded image
- From: Craig Hunter <email@hidden>
- Date: Mon, 28 Mar 2005 09:21:58 -0500
> Message: 10
> Date: Mon, 28 Mar 2005 18:52:54 +1000
> From: Rakka <email@hidden>
> Subject: Re: NSAttributedString with embedded image
> To: email@hidden
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset="us-ascii"
>
>
> On Mar 28, 2005, at 2:32 PM, Craig Hunter wrote:
>
>> I am trying to add a menu item to an app's dock menu with an image and
>> text.
>> I have it working well with text only. My understanding is that to
>> add both
>> an image and text to a dock menu item, I need to use an
>> NSAttributedString
>> that contains both the image and the text. Sounds easy enough, but I
>> have
>> been unable to construct an NSAttributedString with an embedded image
>> and
>> text.
>>
>> Anybody have a code example of constructing an NSAttributedString with
>> an
>> embedded image and some text? BTW, my image is included in the app's
>> bundle
>> as a resource.
>>
>> thanks,
>> Craig
>>
>
> hi,
>
> I would just create an outlet in IB (e.g theItem) connecting it to the
> menu item you want. Then in Xcode, declare an NSImage (e.g image) and
> NSString (e.g imagePath), then initWithContentsOfFile.
>
> imagePath = [[NSBundle mainBundle] pathForResource:@"MyImage"
> ofType:@"tif"];
> image = [[NSImage alloc] initWithContentsOfFile:imagePath];
>
> After that, use [theItem setImage:image];
>
> Hope that helps.
>
> Regards,
>
> Rakka
I should note that the dock menu in my app is dynamic -- the number of menu
items (aside from the standard app menu items) changes from zero up to 5 or
6 at a time, and the names/images would change too. So, as far as the
NSMenu and NSMenuItem creation goes, I am doing everything in code.
I did try using a [theItem setImage:image] approach -- right after I create
a menu item and set it's title, I tried setting it's image in the same
fashion you recommend. Did not seem to work (maybe that would have been
just too easy!!), and then I came across a post in the archives where it was
recommended to use NSAttributedString (and NSMenuItem's setAttributedTitle:
method) to set dock menu items with images and text. So that's my next
approach but I haven't been able to formulate NSAttributedString with an
embedded image and some text.
Thanks!
Craig
--
Dr. Craig Hunter
NASA Langley Research Center
AAAC/Configuration Aerodynamics Branch
email@hidden (new!!)
(757) 864-3020
(Dual G4 - OS X)
_______________________________________________
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