Thursday, December 8, 2016

Part 2 - UIView's Semantic Property

Semantic is the second property on the UIView's Attribute Inspector. Also called semanticContentAttribute in code.

Semantic means "relating to meaning in language or logic".

This seems like a poorly chosen word since, as you will see, this has more to do with languages rather than meanings in languages.

Semantic

When your app is used on a device that is set to a language that reads from right to left (like Arabic), iOS will automatically flip controls to the other side of the screen to help make it more natural looking for those users.

Using the Semantic property you can override this default behavior.

How to Flip

  • Provide a leading and trailing constraint
  • Leave label/textview's text alignment on "Natural":

Flipping Images

Thanks to wakachamo (comments below) I learned that you can flip images through the assets catalog.

Prevent Flipping

  • Manually setting a label/textview's text alignment
  • If you have constraints on controls, you may have to change the parent's Semantic property from "Unspecified"
  • Changing the Semantic property to anything but "Unspecified"

Other Observations/Notes


3 comments:

  1. If images are in an asset catalog, you can mark them as automatically flippable using the 'Direction' property. :)

    ReplyDelete

Note: Only a member of this blog may post a comment.

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...