How can we achieve large font accessibility in Xamarin.iOS? - xamarin

My application is developed using Xamarin.iOS and I need to make it accessible. We couldn't find any help to achieve large text accessibility in xamarin.iOS. I found this link which explains how to achieve it in Xamarin.Forms and this about MonoTouch. Could someone help me how to achieve Large text accessibility on Xamarin.iOS.

Assign one of the UIFontTextStyles to your UI elements and when the app starts the element's text size will be set based upon the UIFontTextStyle and the user's current Accessibility Larger Text setting:
var uiLabel = new UILabel(new CGRect(40, 40, 200, 40));
uiLabel.Text = "StackOverflow";
uiLabel.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Body);
View.AddSubview(uiLabel);
If you want to dynamically response to the Accessibility Larger Text changes so the user does not have to restart your app, subscribe to UIContentSizeCategoryDidChangeNotification and update your views:
NSNotificationCenter.DefaultCenter.AddObserver(
new NSString("UIContentSizeCategoryDidChangeNotification"),
(NSNotification obj) =>
{
Console.WriteLine("Update layouts/subviews/layers/etc...");
View.SetNeedsLayout();
},
null
);

MonoTouch and Xamarin.iOS are the same thing, just a different name.
It is achieved in the exact same way, where you set the Font property of your UILabel or UITextField to one of the available fonts in the UIFont static class like so:
var label = new UILabel
{
Font = UIFont.PreferredBody
};
This should automatically scale the fonts according to your Accessibility settings on iOS.

Related

macOS Big Sur toolbar item width with image

I'm trying to create an NSToolbar with items similar to the Apple's Mail app on macOS. I have an issue with the default toolbar item's width though, as it seems to be inconsistent. Since Big Sur, the items are meant to be sized automatically by AppKit and the NSToolbarItem minSize, maxSize properties have been deprecated.
I'm setting the image property for each NSToolbarItem, not using custom views. As you can see in the screenshots below, the envelope icon has a different "highlight" area (less padding on the sides) while the trash icon has a much larger highlight area.
The envelope icon is a single NSToolbarItem while the archive box and trash items are displayed using NSToolbarItemGroup with NSSegmentedControl view.
In the Apple's Mail app, even single toolbar items have the same width as the grouped items:
How to increase the toolbar item's width when using an image instead of custom view?
Deprecating a property and leaving you in the dark how to achieve a until recently simple effect without using the deprecated property is typical for how Apple deals with AppKit nowadays.
I would not be surprised of the Mail app still uses the deprecated minSize property, or that the NSToolbarItem objects are based on NSButton views with a minimum width NSLayoutConstraint (which is my current solution).
To continue using minSize without deprecation warnings, you can consider to use a simple ToolbarItem class like this:
class ToolbarItem: NSToolbarItem {
override var minSize: NSSize {
get {
return NSSize(width: 50, height: 30)
}
set {}
}
}

Xamarin.Forms how to change default blue color on ios

I'm creating mobile app in Xamarin.Forms. I have a problem with ios implementation, I need change default blue color in all button texts, switch etc. to my own color.
In Android I managed this by changing styles.xml and colors.xml but on iOS I have no idea how to change this.
Anyone know what and where I have to change?
From the document:
iOS lets you apply visual property settings at a static class level
rather than on individual objects so that the change applies to all
instances of that control in the application.
This functionality is exposed in Xamarin.iOS via a static Appearance property on all UIKit controls that support it.
So you can set the default appearance values in the first screen:
// Set the default appearance values
UIButton.Appearance.TintColor = UIColor.LightGray;
UIButton.Appearance.SetTitleColor(UIColor.FromRGB(0,127,14), UIControlState.Normal);
UISlider.Appearance.ThumbTintColor = UIColor.Red;
UISlider.Appearance.MinimumTrackTintColor = UIColor.Orange;
UISlider.Appearance.MaximumTrackTintColor = UIColor.Yellow;
UIProgressView.Appearance.ProgressTintColor = UIColor.Yellow;
UIProgressView.Appearance.TrackTintColor = UIColor.Orange;
You can also customize the color by :
UIButton button = new UIButton();
button.SetTitleColor(UIColor.Red, UIControlState.Normal);

How to set the layer.borderColor of a UITextField using User Defined Runtime Attributes, for Xamarin?

I can't seem to set the layer.borderColor in XCode.
Most resources online seem to indicate that borderColor is of type CGColor, and that XCode applies UIColors. They say you can get around this by using proxy properties, but they only offer guides in Objective C and Swift:
Is it possible to set UIView border properties from interface builder?
C# has no concept of extension properties, meaning I can't port the above code.
I've made sure my border width is set to 1, which makes a black border appear around the UITextField.
Is there anyway to achieve this from the storyboard or xib file, rather than doing it programatically?
You can open the storyboard file in the Xcode interface builder to set them there. The changes should reflect over into Xamarin.
Alternatively, if what you're having trouble with is just using a CGColor for layer.BorderColor, you can simply get the CGColor property from your UIColor.
As an example:
view.layer.BorderColor = UIColor.Black.CGColor;

Why would dragging a Xamarin scrollview not work when the mouse does work

I have a very simple Xamarin forms app which contains a scrollview, and inside is a stacklayout.
When deployed on Windows, the mouse works correctly to scroll the scrollview with a scrollbar. However, touch/drag does not work at all to scroll the same control. Do I have to do something special to enable touch/drag to scroll? I figured this would just work.
I'm not sure even where to start troubleshooting.
I am targeting Windows 10. Other platforms optional at this point.
The structure of UI classes I have is this:
ContentPage.Content = StackLayout1
StackLayout1.Children = { StackLayout2, Scrollview }
StackLayout2 contains an entry field and two buttons
ScrollView, which is the problem, contains another StackLayout
Inside that I have some labels and some grids
Following is a simplified repro. Running in the android emulator on my (touch capable) dev machine scrolling with touch works, running in the Windows 8.1 emulator, scrolling only works with a mouse, not with touch.
public App() {
StackLayout sl = new StackLayout();
for (int i = 1; i < 20; i++) {
sl.Children.Add( new Label { Text = "Label1", FontSize = 50, HeightRequest = 100 } );
}
ScrollView sv = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand };
sv.Content = sl;
ContentPage cp = new ContentPage();
cp.Content = sv;
MainPage = cp;
}
Does Xamarin not handle Windows devices with touch, like Surface or other windows tablets? Or?
There is an overriden method from Activity which is: public boolean onTouchEvent(MotionEvent event)
This is the general method that interprets all the touch events from the whole screen.
As you know every View has its own onTouchEvent() method that you could implement in order to add some custom implementation.It appears that these touch events go from the "inside" elements to the "outside" elements. I mean parent-child relations.
So in our case, the ScrollView returns true when the touch events are a horizontal. The activity's touch event will be handled only if the ScrollView touch event is not handled by itself then you are fine. Otherwise you have to override and implement the on touch event of scroll view and in some cases you have to return false so as for the whole layout to implement it.
The solution is to update Xamarin v2.0.0.6482, which came with my VS 2015 template, to v2.1.0.6529. Updating is a bit of a pain because of this problem https://bugzilla.xamarin.com/show_bug.cgi?id=39721. Once I got that installed scrolling started working with no other changes.
Scrolling is broken in the older version, on Windows, verified by a dev on the Xamarin forums.

Is there predefined NSColor for the Dock and Menubar on OS X?

There are some NSColor initialization helpers like controlColor() which return various colors of system components. Is there any such thing for the dock and menubar? I couldn't see one by name that popped out. If there is no such helper, is there another way to get the color?
I want to use it as the default NSWindow background color for a utility application I am developing that will be displayed in a small, borderless NSWindow.
They are both controlled from the 'General' panel in 'System Preferences' shown in the figure below.
Thanks in Advance.
No, the menu bar and Dock background appearances aren't NSColor system colors. They do look a lot like the Dark Vibrant and Light Vibrant styles you can get from NSVisualEffectView, though.
If you want to change your view's appearance to match the state of the "Use dark menu bar and Dock" preference... well, there's no API for that, but you can read that preference from where it's stored. (Since it's not API, caveat emptor: there's no guarantee the preference storage won't change in later OS X versions.)
In Swift (and broken into several lines for clarity):
let defaults = NSUserDefaults.standardUserDefaults()
let globalPrefs = defaults.persistentDomainForName(NSGlobalDomain)!
let interfaceStyle = globalPrefs["AppleInterfaceStyle"]
if interfaceStyle as! String == "Dark" {
// time to be all emo
}

Resources