Added support for AutoLayout matching UIPageControl #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to work properly in AutoLayout,
SMPageControl
needed an implementation ofintrinsicContentSize
, a straightforward adaptation ofsizeThatFits:
. Otherwise the height will be ambiguous, requiring the app to set a height constraint. However, doing so doesn't jive well with hiding the page control.To match the behavior of
UIPageControl
, the intrinsic height is set to zero when the control should be hidden due to the number of pages (UIPageControl
is always hidden in this way for zero pages, otherwise depends onhidesForSinglePage
). This is convenient in the case where a constraint has been added, for example, between the top of the page control and the bottom of some other view. When the page control is hidden, the other view can adjust to fill the now vacant space.As a minor convenience, the
MIN_HEIGHT
constant has been updated to aminHeight
property. This allows easier customization of the control in situations where it is merely for display purposes and not receiving user interaction. In my case, the page control is being set touserInteractionEnabled = NO
so that the minimum height can be reduced. Similarly if the page control is adjacent to another control like a tab bar, the height may be increased to enlarge the touch target.