Re: Getting accurate bounds for glyph range
Re: Getting accurate bounds for glyph range
- Subject: Re: Getting accurate bounds for glyph range
- From: Jeremy Dronfield <email@hidden>
- Date: Tue, 2 Mar 2004 20:25:36 +0000
On 2 Mar 2004, at 6:21 pm, Allan Odgaard wrote:
On 2. Mar 2004, at 18:56, Jeremy Dronfield wrote:
I'm experimenting with Matt Gemmell's Rounded Floating Panel, using
it to display text instead of icons (sort of like the Large Type
display in Address Book). To this end, I've inserted a transparent
text view in place of the image view supplied. The point where I run
into trouble is getting the text view to resize accurately to the
bounds of its text storage. [...]
I don't know if there is any particular reason you use text view,
A temporary outbreak of stupidity, I think.
if not, then NSTextField has a sizeToFit method that you can use,
might be easier.
After posting, I did try a version using a text field, but still
couldn't make it work because, for certain reasons (see above), I
forgot about sizeToFit. It works just fine now. Thank you for drawing
it to my attention. The rewritten code is included below in case anyone
is interested.
- Jeremy
PS - It looks lovely.
------------------------------------------
NSDictionary *attributes = [NSDictionary dictionaryWithObjects:[NSArray
arrayWithObjects:[NSFont fontWithName:@"Lucida Grande Bold" size:54.0],
[NSColor whiteColor], nil] forKeys:[NSArray
arrayWithObjects:NSFontAttributeName, NSForegroundColorAttributeName,
nil]];
NSAttributedString *string = [[NSAttributedString alloc]
initWithString:@"A Sample String" attributes:attributes];
NSTextField *textField = [[NSTextField alloc] init];
[textField setAttributedStringValue:string];
[textField sizeToFit];
[textField setBackgroundColor:[NSColor colorWithCalibratedWhite:0.0
alpha:0.35]];
[textField setBordered:NO];
[textField setEditable:NO];
[[self window] setFrame:NSMakeRect(0, 0, [textField frame].size.width +
25, [textField frame].size.height + 25) display:YES];
NSRect centeredRect = [textField frame];
centeredRect.origin.x = (([[self window] frame].size.width -
centeredRect.size.width) / 2.0);
centeredRect.origin.y = (([[self window] frame].size.height -
centeredRect.size.height) / 2.0);
[textField setFrameOrigin:centeredRect.origin];
[roundedView addSubview:textField];
[textField release];
[string release];
------------------------------------------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.