Accessibility Identifier Generation - ios

Certain testing and UI libraries require accessibility identifiers to be set for UI components in storyboards or xibs. I'd like to convert an entire project with some convention like using the mapped property name for the identifier, but anything would be useful. Is there a way to automatically generate accessibility identifiers for xib/storyboard defined views in a project?

I don't know of a way to do this in Xcode so I think you'd have to write a small script or program to manipulate the plist files directly.
Another alternative is to set the identifiers programatically. You could write a helper function to walk the view hierarchy and for any elements where an accessibility label is set, set the identifier (using whatever convention you like), this would be called from viewDidLoad.

Related

Do I really need to add the same element twice, one for each UIStoryboard language file?

I am working in an internationalized Xcode project with two UIStoryboard files en.lproj/Main.storyboard and nl.lproj/Main.storyboard.
Is the consequence of this, that if I want to add a new element, say a UIButton to the storyboard, I have to add it twice, one for each file (and thus set the constraints etc also twice)?
This is how it looks in the navigator:
But selecting the base file actually selects the en.lproj/Main.storyboard, and after adding a button there it looks like I have to follow the same process in the other file.
Is this just the way it works?
No. The usual way is that you only have one storyboard that contains all the UI elements, constraints etc. in your "Base" language (e.g. English). For every additional language (e.g. German) you have a strings file that contains translations for all the texts (buttons, labels etc.) in your storyboard.

Storyboard access UIControl property through global value

I have an iPhone app with a number of view controllers. Their respective UI is setup in the main storyboard file. For consistency, I have defined some global values for textfield heights, font sizes, button heights etc. that will be used by many controls. The current way of setting up these controls is by initialising them in the storyboard and then in the respective view controller, within viewDidAppear, the global values for heights, fonts and the like are accessed and assigned as the remaining properties of these controls.
But this process is fragmented and prone to error. Is there a better way of doing this? Is it possible to have access to global values, defined in swift files, within the storyboard? For instance, could the font of a textfield pointed to by the Attributes Inspector be actually referencing a global value?
Thanks
There is no way to set what you want , if you have a pre-defined height/Font , then set it directly in attributes inspector , if you want to configure for different devices you can try with size classes
Or
Create sub classes of the elements you want ( UITextField / UIIButton ) , and assign them to class name in IB
A possible solution would be to pre-process the story board file. Run a script that searches the related XML elements in the storyboard file and replaces them with the correct values. You may want to add it as a run-script phase so it would run before each compilation (I have not tried that one but it seems possible, though you would not see the fixed values in storyboard while developing), or just run it manually from the command line.

Swift Build Dynamic Apps

I want to develop an app, which can be modified programmatically. In my config.swift file, I save the main settings for my app. For example: If I want to create 5 textfields, I set a variable for that (in config.swift) and this will create me five textfields. This works perfectly! But as I do everything programmatically (e.g. adding textfields), I don't have the advantages of the visual storyboard. Is there a way to create UIElements dynamically, without dispensing the advantages of a storyboard?
Everything you can create in the Storyboard can be created in code. When you create your Storyboard it is set with that structure, but when you create it programmatically it´s more dynamic and you can create elements "on the fly".
The main advantage with the Storyboard is that you get a visual overview of your layout. Up to you to choose what suits your needs best.

How to override cell style for xib-less cell inherited from MvxBindableTableViewCell

I'm trying to inherit from MvxBindableTableViewCell to redefine my own cell (with more text fields and images).
When a new instance is created from MyCustomSource.GetOrCreateCell, the ctor used is always MyCustomCell(IntPtr handle). In this case, the cell style used is Default, but I want to use the Value1 style (to reuse the right-aligned blue text).
In a traditional iOS app, the solution will be to use from my ctor the "initWithStyle:reuseIdentifier:" base ctor.
For a MonoTouch/MvvmCross project, the right solutino will be probably to do it in the XCode designer. But I'm working from VS (cannot use my solution with XS) and I want to use only xib-less UI to be able to track changes on them in my source control.
Any idea on how to achieve my aim?
Guillaume.
Personally, I don't tend to use the standard cell types very much. Instead I tend to build my own custom cells using either XIB or manual-code-based layout.
However, you can easily use the standard cell types if you want to in Mvx.
In v3, you can choose to use the MvxStandardTableViewCell constructor which takes a UITableViewCellStyle as a parameter - e.g. see https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxStandardTableViewCell.cs#L40
This is also exposed up to the constructors for the MvxStandardTableViewSource https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxStandardTableViewSource.cs#L60
In vNext last year, I think the same functionality was exposed via the old MvxSimpleBindableTableViewSource - see https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxSimpleBindableTableViewSource.cs#L62

Settings style form in app

Is there an easy way to a Settings.bundle style form in an app? I have seen InAppSettingsKit, but I just want to create a form for data entry that has some nested pickers and other features simple to implement with Settings.bundle.
It is very easy to achieve, the settings screens are simply grouped table views with the standard styling.
With storyboards, the "static" content feature makes it even easier - this mode allows you to specify the contents of each cell right there in the storyboard, you don't need any datasource methods and can do it all via outlets. There is a good tutorial on Ray Wenederlich here

Resources