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)

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


Attachments

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 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

Note You need to log in before you can comment on or make changes to this bug.