• 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: Drawing boxes around each digit entered in UITextField (Number Pad)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing boxes around each digit entered in UITextField (Number Pad)


  • Subject: Re: Drawing boxes around each digit entered in UITextField (Number Pad)
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 10 Feb 2019 09:22:21 -0800

On Feb 9, 2019, at 12:36 , Devarshi Kulshreshtha <email@hidden>
wrote:
>
> Am I missing any important property in X axis from the calculation due to
> which I am unable to get properly aligned bounding box over each digit?

Yes, you’re Doing It Wrong™. :)

Glyphs are laid out along the line according to their advance widths, not their
bounding box widths. That means the *width* of the box you draw should be the
advance width (minus any thickness of the box border that lies outside the box
rect, minus any spacing you want between the boxes horizontally). The *height*
of the box should be something big enough to hold the digit (e.g. font ascent +
font descent). The *origin offset* of the box should be a multiple of the
advance width.

https://developer.apple.com/documentation/coretext/1511265-ctfontgetadvancesforglyphs

<https://developer.apple.com/documentation/coretext/1511265-ctfontgetadvancesforglyphs>

This is still going to be problematic sometimes, depending on the font. There’s
nothing preventing glyphs from being wider than their advance width, and you
have no control over that. Also, there’s no guarantee that all the digits have
the same advance width (“lining numerals”), although it’s typically true of
fonts made for use on computers. You might want to force a monospaced font for
the text field. Also, be careful with non-Roman fonts: the conventions for
digits might be different.
_______________________________________________

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

References: 
 >Drawing boxes around each digit entered in UITextField (Number Pad) (From: Devarshi Kulshreshtha <email@hidden>)

  • Prev by Date: Re: Drawing boxes around each digit entered in UITextField (Number Pad)
  • Next by Date: Silly question on extending NSObject.
  • Previous by thread: Re: Drawing boxes around each digit entered in UITextField (Number Pad)
  • Next by thread: Silly question on extending NSObject.
  • Index(es):
    • Date
    • Thread