diff --git a/src/UIKit/UIContentSizeCategory.cs b/src/UIKit/UIContentSizeCategory.cs new file mode 100644 index 0000000000..2e9b6b38b2 --- /dev/null +++ b/src/UIKit/UIContentSizeCategory.cs @@ -0,0 +1,46 @@ +#if !WATCH + +using System; +using System.Runtime.InteropServices; + +using XamCore.ObjCRuntime; +using XamCore.Foundation; + +namespace XamCore.UIKit { + static public partial class UIContentSizeCategoryExtensions { + + [iOS (11, 0), TV (11, 0)] + [DllImport (Constants.UIKitLibrary)] + static extern nint /* NSComparisonResult */ UIContentSizeCategoryCompareToCategory (IntPtr /* NSString */ lhs, IntPtr /* NSString */ rhs); + + [iOS (11, 0), TV (11, 0)] + public static NSComparisonResult Compare (UIContentSizeCategory category1, UIContentSizeCategory category2) + { + var c1 = category1.GetConstant (); + if (c1 == null) + throw new ArgumentException ($"Unknown 'UIContentSizeCategory' value", nameof (category1)); + + var c2 = category2.GetConstant (); + if (c2 == null) + throw new ArgumentException ($"Unknown 'UIContentSizeCategory' value", nameof (category2)); + + return (NSComparisonResult)(long)UIContentSizeCategoryCompareToCategory (c1.Handle, c2.Handle); + } + + [iOS (11, 0), TV (11, 0)] + [DllImport (Constants.UIKitLibrary)] + static extern bool UIContentSizeCategoryIsAccessibilityCategory (IntPtr /* NSString */ category); + + [iOS (11, 0), TV (11, 0)] + static public bool IsAccessibilityCategory (this UIContentSizeCategory self) + { + var c1 = self.GetConstant (); + if (c1 == null) + throw new ArgumentException ($"Unknown 'UIContentSizeCategory' value"); + + return UIContentSizeCategoryIsAccessibilityCategory (c1.Handle); + } + } +} + +#endif // !WATCH diff --git a/src/frameworks.sources b/src/frameworks.sources index 197eb22ae6..99dd875e1f 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1360,6 +1360,7 @@ UIKIT_SOURCES = \ UIKit/UICollectionViewLayoutAttributes.cs \ UIKit/UICollectionViewTransitionLayout.cs \ UIKit/UIColor.cs \ + UIKit/UIContentSizeCategory.cs \ UIKit/UIControl.cs \ UIKit/UIDevice.cs \ UIKit/UIDocumentInteractionController.cs \ diff --git a/tests/monotouch-test/UIKit/UIContentSizeCategoryTest.cs b/tests/monotouch-test/UIKit/UIContentSizeCategoryTest.cs new file mode 100644 index 0000000000..88bcf86048 --- /dev/null +++ b/tests/monotouch-test/UIKit/UIContentSizeCategoryTest.cs @@ -0,0 +1,51 @@ +// +// Unit tests for UIContentSizeCategory +// +// Authors: +// Vincent Dondain +// +// Copyright 2017 Microsoft. All rights reserved. +// + +#if !__WATCHOS__ + +using System; +using Foundation; +using NUnit.Framework; +using UIKit; + +namespace MonoTouchFixtures.UIKit { + + [TestFixture] + [Preserve (AllMembers = true)] + public class UIContentSizeCategoryTest { + + [SetUp] + public void Setup () + { + TestRuntime.AssertXcodeVersion (9, 0); + } + + [Test] + public void IsAccessibilityCategory () + { + var isAccessible = UIContentSizeCategory.AccessibilityMedium.IsAccessibilityCategory (); + Assert.IsTrue (isAccessible, "AccessibilityMedium"); + isAccessible = UIContentSizeCategory.Medium.IsAccessibilityCategory (); + Assert.IsFalse (isAccessible, "Medium"); + } + + [Test] + public void Compare () + { + var small = UIContentSizeCategory.Small; + var large = UIContentSizeCategory.Large; + Assert.True (UIContentSizeCategoryExtensions.Compare (small, large) == NSComparisonResult.Ascending, "small < large"); + Assert.Throws (() => UIContentSizeCategoryExtensions.Compare ((UIContentSizeCategory)31415, large)); + Assert.Throws (() => UIContentSizeCategoryExtensions.Compare (small, (UIContentSizeCategory)271828)); + Assert.Throws (() => ((UIContentSizeCategory)1234).IsAccessibilityCategory ()); + } + } +} + +#endif // !__WATCHOS__ diff --git a/tests/monotouch-test/monotouch-test.csproj b/tests/monotouch-test/monotouch-test.csproj index 97a234abe7..ac303b0951 100644 --- a/tests/monotouch-test/monotouch-test.csproj +++ b/tests/monotouch-test/monotouch-test.csproj @@ -700,6 +700,7 @@ +