Fixed font width

  • How do i specify fixed font width for an nsattributedstring (used to set string to nstextfield) ?

    Thanks in Advance

     
         P.Rajendran or Raju      

    (for further details contact
    me )        
  • On Jun 6, 2012, at 9:25 AM, Rajendran P wrote:

    > How do i specify fixed font width for an nsattributedstring (used to set string to nstextfield) ?

    First, perhaps you just want to use a fixed-width font instead of setting a fixed width on a non-fixed-width font.

    Anyway, I think you use the font attribute NSFontFixedAdvanceAttribute.  So, you either construct a NSFontDescriptor from scratch and include that attribute, or you start from an NSFont, get its fontDescriptor, and then use -fontDescriptorByAddingAttributes: to create a new font descriptor with that attribute.  Then, you use +[NSFont fontWithDescriptor:size:] to get an NSFont and set it on the attributed string with NSFontAttributeName.

    Regards,
    Ken
  • On Jun 6, 2012, at 7:46 AM, Ken Thomases wrote:

    > First, perhaps you just want to use a fixed-width font instead of setting a fixed width on a non-fixed-width font.

    That's almost always the best way to go. Forcing a proportional font to use fixed character widths generally looks really ugly. Fixed-width fonts like Courier or Menlo may not look as pretty as proportional fonts, but they were at least designed to look reasonable with those character widths.

    —Jens
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today