A couple of things to note:

1. In the SF font, colons are vertically centered by default.
You can test this by creating a plain UILabel with System Font in IB and type a 
time e.g. 10:20, and notice the colon is vertically centered. So if you use SF 
font, you don't have to do anything to get the centered colon feature.

2. The font for UILabel with an attributed string 'text' property appears NOT 
to be SF font (e.g. System Font) by default.
Again, to test this create a UILabel in IB and change Text to an attributed 
string, notice that the font changes to Helvetica Neue. I also notice that SF 
font doesn't show up in the list of fonts in IB for this label. FWIW, I'm still 
using Xcode 7.x so someone should try Xcode 8 to verify if this is still the 
case.
For the heck of it I installed SF font on my Mac so I can select it in the 
attributed text font list, but notice a bunch of bugs. For example, the font 
size I set in IB for the attributed text is ignored. At runtime it's probably 
12 or 14 pt. Also, in IB, if you edit the text by double-clicking in the label, 
you'll see an input field for large text but nothing shown. Oh well, another 
trip to RADAR.
In any case it's a bad idea to select the exact font since you have to choose 
SF Display or Text which you don't want to do. It should be dynamically 
selected at runtime based on the font size. This behavior is supported by using 
System Font.

Anyways, I would check the font at runtime to make sure it's SF. Otherwise, you 
need a font that supports the Vertically Centered Colon font feature. You can 
check this feature by doing the following:
• Select your desired font on your Mac for the attributed string in the font 
panel
• Click the Gear icon in the upper-left corner.
• Select Typography…
• Select 'Alternative Stylistic Sets'
• Select 'Vertically Centered Colon'

Which Helvetica Neue DOES NOT support.

Furthermore, I don't see a way to set these  'Alternative Stylistic' attributes 
from UIAttributedText. I do see some settings in CoreText/SFNTLayoutTypes.h 
under kStylisticAlternativesType. But the settings are just numbered so I don't 
know which it might be. A little experimentation might find the right one.

But in summary, if you are using SF font, you don't need to set the Vertically 
Centered Colon attribute as it should be on by default.

Doug Hill



> On Nov 28, 2016, at 11:12 AM, Gerriet M. Denkmann <gerri...@icloud.com> wrote:
> 
> 
>> On 28 Nov 2016, at 23:42, Alastair Houghton <alast...@alastairs-place.net> 
>> wrote:
>> 
>> On 28 Nov 2016, at 16:18, Gerriet M. Denkmann <gerri...@icloud.com> wrote:
>>> 
>>> 
>>>> On 28 Nov 2016, at 22:13, Eric E. Dolecki <edole...@gmail.com> wrote:
>>>> 
>>>> You could probably use an attributed string and add an attribute for the 
>>>> last colon: NSBaselineOffsetAttributeName
>>> 
>>> Yes; but this would be some rather desperate work-around.
>>> 
>>> I was rather thinking of UIFontDescriptorFeatureSettingsAttribute with some 
>>> Feature type from SFNTLayoutTypes.h (in CoreText).
>>> I tried a few types, but no success so far.
>> 
>> The problem you’ve got is that unless the font has a feature that 
>> specifically allows you to change *any* colon (as opposed to a colon between 
>> two numerals), you aren’t going to be able to do it by turning on an 
>> OpenType feature.  Even if you can, there doesn’t appear to be a standard 
>> feature code for this, so you’d be reliant on Apple not changing it in the 
>> future.
> 
> The WWDC 2015 talk seemed to suggest that there is a standard feature for 
> this.
> But there are about 40 feature types in SFNTLayoutTypes.h - no idea what to 
> use.
> 
> 
>> What you *could* do instead is get Core Text (or Cocoa Text) to lay out a 
>> string e.g. “12:00”, then grab the glyph for the centred colon directly from 
>> that string and use it explicitly, e.g. by attaching a 
>> kCTGlyphInfoAttributeName attribute to your string with the value set to an 
>> appropriately constructed CTGlyphInfoRef.
> 
> done once:
> 
> CGRect frame = { {0,0},{99,99}};      
> UITextView *dummyTextView = [ [UITextView alloc] initWithFrame: frame 
> textContainer: nil ];
> dummyTextView.text = @“23:21”;
> dummyTextView.font = thinFont;
> NSLayoutManager *layoutManager = dummyTextView.layoutManager;
> [ layoutManager ensureGlyphsForCharacterRange: range ];
> [ layoutManager ensureLayoutForCharacterRange: range ];
> NSUInteger glyphIndex = [ layoutManager glyphIndexForCharacterAtIndex: 2 ];
> centeredColonGlyph = [ layoutManager CGGlyphAtIndex: glyphIndex ];;
> 
> 
> and then:
> 
> CFMutableAttributedStringRef aStr = (__bridge 
> CFMutableAttributedStringRef)attributedString;
> CTFontRef fontRiff = (__bridge CTFontRef)thinFont;
> CTGlyphInfoRef glyInfRef = CTGlyphInfoCreateWithGlyph( centeredColonGlyph, 
> fontRiff, (CFStringRef)@":" );
> CFRange range = { (CFIndex)colonIndex, 1 };
> CFAttributedStringSetAttribute( aStr, range, kCTGlyphInfoAttributeName, 
> glyInfRef );
> CFRelease(glyInfRef);
> 
> This seems to be working. Nut sure whether there is a more elegant way.
> 
> Thanks a lot for your help!
> 
> 
> Kind regards,
> 
> Gerriet.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to