views:

73

answers:

1

UIControl has two properties that are documented to affect the layout of content in the control's view:

contentHorizontalAlignment

The horizontal alignment of content (text or image) within the receiver.

controlVerticalAlignment

The vertical alignment of content (text or image) within the receiver.

I have a UIControl subclass that manages a set of five subviews; each subview is a custom UIView subclass (i.e. not a UILabel or UIImageView).

The behavior I'd like to get is UIControl managing the layout of my custom subviews using the contentHorizontalAlignment and contentVerticalAlignment properties.

From my experimentation, it does not appear that UIControl actually honors either of these property values when doing subview layout, at least when the subview's are not labels or images. I'm not 100% sure that my subclass is properly implemented, though.

My questions are three-ish:

  1. Does UIControl implement any layout behavior around these properties?
    • Is it only for subviews that are UILabel and UIImageView?
  2. Do I have to provide the implementation for subview layout in my UIControl subclass?
  3. Are these properties present in the UIControl base class mainly to provide a caller's with a consistent API for managing content?

I'm expecting UIControl to provide some kind of base-level layout behavior given the presence of contentHorizontalAlignment and contentVerticalAlignment properties.

Am I off-base? I don't object to implementing my own layout behavior. I just don't want to be fighting the framework if UIControl already provides some layout behavior that I should be using.

Thanks,

Bill

+1  A: 

Just to follow up on this...

UIControl just provides these properties as a consistent API for subclasses. The base class doesn't do anything with them.

In your UIControl subclass, override the -layoutSubviews method and use the properties to guide your layout logic.

e.g.

switch (self.contentHorizontalAlignment) {
    case UIControlContentHorizontalAlignmentCenter:
    // layout logic for centering
    break; 
}
Bill Garrison