uiviewautolayout

How to create a custom UIView that defines a baseline?


Using the NSLayoutConstraint class, it is possible to create a constraint that is based on a view's baseline (NSLayoutAttributeBaseline). However, I haven't seen any documentation that describes how a UIView actually provides a baseline value to the auto layout system.

If I wanted to create a custom UIView subclass that defines a baseline, how would I do it? NSView defines a baselineOffsetFromBottom method that I assume is involved somehow on OS X, but how does this work in iOS?


Solution

  • From the UIView docs:

    viewForBaselineLayout

    Returns a view used to satisfy baseline constraints.

    - (UIView *)viewForBaselineLayout

    Return Value

    The view the constraint system should use to satisfy baseline constraints