Wednesday, July 18, 2012

Am I wider or taller?

Within a UIView (or subclass) you have access to a 'bounds' property.  You can use this to determine whether or not you are wider or taller:

- (NSString *) amIWiderOrTaller {
  if (self.bounds.size.width==self.bounds.size.height) {
    return @"Same";
  } else if (self.bounds.size.width > self.bounds.size.height) {
    return @"Wider";
  } else {
    return @"Taller";
  }
}

- (CGPoint) getMidpoint
{
  CGPoint midPoint;
  midPoint.x = self.bounds.origin.x + self.bounds.size.width/2;
  midPoint.y = self.bounds.origin.y + self.bounds.size.height/2;
  return midPoint;
}

No comments:

Post a Comment