We need to use a UITextView
(i.e. multi-line text entry) to allow the user to enter information. UITextView
doesn't work nicely with autoresize, so we set the constraints using the boundaries of the UIAlertController
view. There are layout issues depending on accessibility settings.
For example, this a layout, nice and neat, under larger text settings:
But using the same constraints, this is what it looks like using default text settings:
Not good! We don't want to get into the rabbit hole of customizing code for each model and text size settings. Is there a legal way to get the views for the message and actions so that we can align to these features instead?
"Legal" because the official documentation for UIAlertController
indicates (emphasis mine):
Important
The
UIAlertController
class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
And have confirmed that the actions (the Cancel
and Submit
buttons) don't seem to be visible when we're iterating through [[alertController view] subviews]
, so we have to be careful here.
Also, safeAreaInsets
is {0, 0, 0, 0}
for all iPhone models, so that's not any help here.
I guess most of the problem is from the stacking of the buttons, so if there is a way to detect that configuration, that would fix most of the layout issue.
It's an older app, so we're coding in Objective-C, but Swift solutions are okay too.
Thank you @DonMag and @rmaddy for your suggestions, but the budget allows for us only to revise the existing UIAlertController
code, as opposed to creating a new view controller.
We reviewed the issue and found that there were only three cases we needed to worry about, specifically the XL
, XXL
, and XXXL
preferred content size categories. We handled them directly:
NSString *sizeCategory = UIScreen.mainScreen.traitCollection.preferredContentSizeCategory;
CGFloat top = -82.f;
CGFloat bottom = +52.0f;
if ([sizeCategory isEqualToString:UIContentSizeCategoryExtraLarge])
{
top = -90.0f;
bottom = +98.0f;
}
else if ([sizeCategory isEqualToString:UIContentSizeCategoryExtraExtraLarge])
{
top = -118.0f;
bottom = +98.0f;
}
else if ([sizeCategory isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge])
{
top = -160.0f;
bottom = +98.0f;
}
Then the code to set up the constraints follows after this. The code already has hard-coded constants, so we aren't making the situation too much worse!
We aren't handling the additional text sizes under "Larger Accessibility Sizes" at this time. The app in general requires a minimum level of visual acuity.