Bug 42967 - We need UIFontTextStyle enum (or constants) for UIFont.GetPreferredFontForTextStyle
Summary: We need UIFontTextStyle enum (or constants) for UIFont.GetPreferredFontForTex...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 9.8 (tvOS / C7)
Hardware: PC Mac OS
: Normal enhancement
Target Milestone: (C9)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2016-08-01 19:49 UTC by Larry O'Brien
Modified: 2016-09-27 18:21 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Larry O'Brien 2016-08-01 19:49:49 UTC
The string constants defined at 

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIFontDescriptor_Class/#//apple_ref/doc/constant_group/Text_Styles

let UIFontTextStyleTitle1: String
let UIFontTextStyleTitle2: String
let UIFontTextStyleTitle3: String
let UIFontTextStyleHeadline: String
let UIFontTextStyleSubheadline: String
let UIFontTextStyleBody: String
let UIFontTextStyleFootnote: String
let UIFontTextStyleCaption1: String
let UIFontTextStyleCaption2: String
let UIFontTextStyleCallout: String

Are required for UIFont.GetPreferredFontForTextStyle
Comment 1 Manuel de la Peña [MSFT] 2016-08-02 08:47:04 UTC
Looking at https://github.com/xamarin/xamarin-macios/blob/master/src/uikit.cs#L4858 I've noticed we do have the constants yet they are internal. I've contacted the bindings author to confirm the reason and will update the code accordingly.
Comment 2 Miguel de Icaza [MSFT] 2016-08-02 15:42:58 UTC
Use the UIFont properties for those names instead, you do not need to call a method that takes an NSString whose value is not discoverable:

On the UIFont class, use one of these properties:

PreferredTitle1
PreferredTitle2
PreferredTitle3
PreferredHeadline
PreferredSubheadline
PreferredBody
PreferredFootnote
PreferredCaption1
PreferredCaption2
PreferredCallout

This information is even documented on the UIFont documentation:

https://developer.xamarin.com/api/type/UIKit.UIFont/

The docs talk about iOS 7 features, some new properties were added in 9.0, which are not listed in the documentation, we should update that.
Comment 3 Larry O'Brien 2016-08-02 15:50:59 UTC
That works if the dev can hard-code the style (UIFont.PreferredHeadline) but does not work if the style is variable (PreferredFontForTextStyle). The source code we show is incorrect:

	headlineLabel.Font = UIFont.PreferredFontForTextStyle(UIFontTextStyle.Headline);
	bodyText.Font = UIFont.PreferredFontForTextStyle(UIFontTextStyle.Body);
  //...etc...
}

But we don't *have* UIFontTextStyle.Headline or .Body (we don't have UIFontTextStyle).
Comment 4 Sebastien Pouliot 2016-08-02 18:33:01 UTC
I think the original issue was misunderstood, the mentioned API requires the NSString constant. However we can expose something better (and enum) in our public API.
Comment 5 Sebastien Pouliot 2016-09-21 00:56:47 UTC
PR https://github.com/xamarin/xamarin-macios/pull/863