• 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: How to draw correct underline ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw correct underline ?


  • Subject: Re: How to draw correct underline ?
  • From: Eric Morand <email@hidden>
  • Date: Thu, 25 Aug 2005 17:39:06 +0200

Now that you American fellows are awake, let me push that question up again ! :o)




Le 25 août 05 à 14:16, Eric Morand a écrit :


Even worse : here is the same view using the code given by Apple (!!!) to draw hyperlink-like text :



- (void)drawRect:(NSRect)rect
{
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"This is a test to show ugly underlining !"];
NSRange selectedRange = NSMakeRange(0,[string length]);


NSMutableDictionary *linkAttributes = [NSMutableDictionary dictionary];
[linkAttributes setObject:@"HTTP" forKey:@"type"];
[linkAttributes setObject:@"http://www.apple.com/"; forKey:@"destination"];
[string beginEditing];
[string addAttribute:NSLinkAttributeName value:linkAttributes range:selectedRange];
[string addAttribute:NSForegroundColorAttributeName value: [NSColor blueColor] range:selectedRange];
[string addAttribute:NSUnderlineStyleAttributeName value: [NSNumber numberWithInt:NSSingleUnderlineStyle] range:selectedRange];
[string endEditing];


    [string drawInRect:rect];
}




Awful !


You can find this sample code in Apple documentation, Attributed Strings Programming Guide, Changing an Attributed String.



It seems like even Apple docs don't know how to draw a correct underline !





I'm pretty sure some of you have underlined texts in their app ! Can't someone help me on this ?







Eric.



Le 25 août 05 à 13:55, Eric Morand a écrit :


Just to give you an easy way to test the ugly underline symptom, here is a custom view that only draw a string underlined :


// // TestView.h // Test // // Created by Eric on 25/08/05. // Copyright 2005 __MyCompanyName__. All rights reserved. //

#import <Cocoa/Cocoa.h>


@interface TestView : NSView {

}

@end


// // TestView.m // Test // // Created by Eric on 25/08/05. // Copyright 2005 __MyCompanyName__. All rights reserved. //

#import "TestView.h"


@implementation TestView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];

    if (self)
    {
    }

    return self;
}

- (void)drawRect:(NSRect)rect
{
[@"This is a test to show the ugly underline !" drawInRect:rect withAttributes:[NSDictionary dictionaryWithObject: [NSNumber numberWithInt:1] forKey:NSUnderlineStyleAttributeName]];
}


@end





Pretty straightforward, right ?



Well, put a custom view in IB, change its class to TestView, compile and launch your app.



I just want perfect underline just like here !



If anyone can help...




Eric.




Le 25 août 05 à 11:20, Eric Morand a écrit :


Hi list !

In the process of underlining the text string of a control, I've noticed that the underline is pretty ugly.

Using the following string attributes :

highlightedStringAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:[self font], NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, [NSNumber numberWithInt:1], NSUnderlineStyleAttributeName, nil] retain];


...the underline drawn under the string when using...


[[self title] drawInRect:textRect withAttributes:stringAttributes];



...is gray (not even constant gray !) instead of black and is not 1 point high but 2 !




Is there a way to draw a correct underline ?


Thanks by advance,

Eric.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com


This email sent to email@hidden







_______________________________________________ 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
  • Follow-Ups:
    • [Moderator] Re-posts (Re: How to draw correct underline ?)
      • From: mmalcolm crawford <email@hidden>
References: 
 >How to draw correct underline ? (From: Eric Morand <email@hidden>)
 >Re: How to draw correct underline ? (From: Eric Morand <email@hidden>)

  • Prev by Date: Re: Finding all subclasses of a class ?
  • Next by Date: LevelWindow for Dashboard?
  • Previous by thread: Re: How to draw correct underline ?
  • Next by thread: [Moderator] Re-posts (Re: How to draw correct underline ?)
  • Index(es):
    • Date
    • Thread