How is this showed up? - ios

I want to make a similar UI like that
Login Screen and you can see when i clicked on an image constraint the attribute inspector shows up one more menu "Adaptive Layout Constraint" Layout.
How is this happened and how i can show up the same menu in my project. Thank you.

It looks like a custom class with #IBInspectable property setAdaptiveLayout
class AdaptiveLayoutConstraint: NSLayoutConstraint {
#IBInspectable
var setAdaptiveLayout: Bool {
set {
//doWhatYouWant
}
get {
//doWhatYouWant
}
}
}

Related

Informing voiceover users that they have highlighted an element within a container

I'm looking to implement something for voiceover users that is similar to how Apple handles the miniplayer in their Music app.
In the miniplayer, there are a number of accessibility elements: the album artwork, the track metadata, the play and forward buttons. When a user first selects an element within the miniplayer, the voiceover reads "Miniplayer; double tap to expand the miniplayer" before giving the label for the element selected. But if you navigate between elements in the miniplayer, it will just give each element's label, trait and hint. It will only provide the Miniplayer (container level) label and hint when you have moved from an element outside the miniplayer to an element inside the miniplayer.
Being able to give this kind of context to voiceover users seems like good UX design, but how is this implemented? I understand how to group elements together by including them in the myItem.accessibilityElements array, but not how to determine whether the current/previous element that the user has selected is part of the same container.
To inform a VoiceOver user that an element has been selected within a container, you could create a class for each kind of element you have in the container (use of generics maybe ???) to override the methods of the UIAccessibilityFocus informal protocol.
Let's take an example assuming that we have only labels in the blue container hereunder (code to be adapted for other kinds of elements) :
Create a class for the labels including a property for the superview it belongs to.
class EltLabel : UILabel {
var containerView: UIView? {
get { return self.superview }
set { }
}
}
Override the UIAccessibilityFocus informal protocol methods in an extension of the new created class.
extension EltLabel {
override open func accessibilityElementDidBecomeFocused() {
if self.accessibilityElementIsFocused() {
// Actions to be done when the element did become focused.
}
}
override open func accessibilityElementDidLoseFocus() {
if self.accessibilityElementIsFocused() {
// Actions to be done when the element did lose focus.
}
}
override open func accessibilityElementIsFocused() -> Bool {
guard let containerView = self.containerView else { return false }
return (self.isDescendant(of: containerView)) ? true : false
}
}
Don't forget to create outlets with your labels and everything is automatically handled.
class BoutonViewController: UIViewController {
#IBOutlet weak var label1: EltLabel!
#IBOutlet weak var label2: EltLabel!
}
This code snippet to be adapted and included in your code environment will inform the VoiceOver users that they have highlighted an element within a container as desired.
Now, if you want to "determine whether the current/previous element that the user has selected is part of the same container", just add a variable in the view controller that will be incremented/decremented every time an element of the container is focused/unfocused (a boolean variable should be enough).

How to localize Accessibility Label(Description) with Interface Builder?

In order to add VoiceOver support for my app(using Interface Builder),I set a button's "Accessibility Identity -> Description" to "Mute" like this.This actually set accessibility label.
And now,I want to add localization for this button,including accessibility label of it.
How can I do that?
ps: I've tried the programmatically way(NSLocalizedString) and creating xib file for each language.But both of them are not good for maintenance.I want to know if I can localize it in ".strings" way
You can create extension like this and then set keys in UI Builder but handle localization in .strings file
#IBDesignable
public extension UIView {
#IBInspectable
var accessibilityLabelKey: String {
get { return "" }
set {
self.accessibilityLabel = NSLocalizedString(newValue, comment:newValue)
}
}
}

Override UI element .enabled property in Swift

I want to override property of UIView class to do extra lines of code each time property value of .enabled is changed. How do I do that?
For example:
There is MyUIView class myClass
There is myClass.enabled property
I want to override this to add next things
Edit subview of type UIView and set background to red colour if enabled/green if disabled.
Edit subview of type UIButton and make it disabled if disabled/enabled if enabled.
The code will look something like this -
class SubClass: UIView {
override var userInteractionEnabled: Bool {
didSet {
// Do the color change and other stuff.
// Use oldValue to access old value
}
}
}
There is much more to explore about this setter and getter.

Can't make User Defined Runtime Attributes work

I would really like to be able to use the "User Defined Runtime Attributes " from xcode Storyboard to build a nice pop up through a container view.
Unfortunately, I can't make it works and can't figure out why !
I found many topics (eg: Is it possible to set UIView border properties from interface builder?) which deal about it but this doesn't work for me... !
Here is the attribute inspector of the containerView embed UIView (I also tried to implement into containerView UIView too with no success).
I added an extension to transform UIColor to CGColor as expected :
extension CALayer {
var borderUIColor: UIColor {
set {
self.borderColor = newValue.CGColor
}
get {
return UIColor(CGColor: self.borderColor!)
}
}
}
Does someone could think about something missing ?
Thank you very much in advance ;)
Instead of layer.borderColor, use layer.borderUIColor in your user defined runtime attributes. Just double click the key name and add UI.

Monotouch: Is it possible to present DialogViewController inside of a usual UIViewController

I need to create login screen for iPad and I need my login inputs to be fixed width.
Is it possible to fix length of DialogViewController elements or create a layout with UIView element and nest DialogViewController in there?
drunkcamel, you can set frame size of view for dialog and add dialog as subview to other view
public class InlineDialogViewController : UIViewController
{
public InlineDialogViewController()
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var dialog = new DialogViewController(null);
dialog.View.Frame = new RectangleF(0,0,100,100); // set custom dialog size
View.AddSubview(dialog.view);
}
}

Resources