From 9b196da5d3191aa6ab018d68151504bd93b665df Mon Sep 17 00:00:00 2001 From: Ben Kreeger Date: Wed, 13 Feb 2013 14:21:31 -0600 Subject: [PATCH] API updates and method renames. --- BDKGeometry.h | 18 ++++++++++++------ BDKGeometry.m | 44 +++++++++++++++++++++++++++++--------------- BDKGeometry.podspec | 4 ++-- readme.markdown | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/BDKGeometry.h b/BDKGeometry.h index 0d57d63..5390e90 100644 --- a/BDKGeometry.h +++ b/BDKGeometry.h @@ -8,42 +8,48 @@ * @param size a new CGSize to assign to `rect`. * @return a new rect with the given size. */ -CGRect CGRectAdjustSize(CGRect rect, CGSize size); +CGRect CGRectSetSize(CGRect rect, CGSize size); +CGRect CGRectAdjustSize(CGRect rect, CGSize size) __attribute__((deprecated)); /** Gives a rect a new origin. * @param rect the rect on which to operate. * @param origin a new origin CGPoint to assign to `rect`. * @return a new rect with the given origin. */ -CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin); +CGRect CGRectSetOrigin(CGRect rect, CGPoint origin); +CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin) __attribute__((deprecated)); /** Gives a rect's size a new width. * @param rect the rect on which to operate. * @param width a new width CGFloat to assign to `rect`. * @return a new rect with the given width. */ -CGRect CGRectAdjustWidth(CGRect rect, CGFloat width); +CGRect CGRectSetWidth(CGRect rect, CGFloat width); +CGRect CGRectAdjustWidth(CGRect rect, CGFloat width) __attribute__((deprecated)); /** Gives a rect a new height. * @param rect the rect on which to operate. * @param size a new height CGFloat to assign to `rect`. * @return a new rect with the given height. */ -CGRect CGRectAdjustHeight(CGRect rect, CGFloat height); +CGRect CGRectSetHeight(CGRect rect, CGFloat height); +CGRect CGRectAdjustHeight(CGRect rect, CGFloat height) __attribute__((deprecated)); /** Gives a rect a new y-origin. * @param rect the rect on which to operate. * @param size a new y-origin CGFloat to assign to `rect`. * @return a new rect with the given y-origin. */ -CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin); +CGRect CGRectSetYOrigin(CGRect rect, CGFloat yOrigin); +CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin) __attribute__((deprecated)); /** Gives a rect a new x-origin. * @param rect the rect on which to operate. * @param size a new x-origin CGFloat to assign to `rect`. * @return a new rect with the given x-origin. */ -CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin); +CGRect CGRectSetXOrigin(CGRect rect, CGFloat xOrigin); +CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin) __attribute__((deprecated)); /** Centers a child (sub) rect inside of a parent (master) rect, using both width and height. * @param subRect the child rect, which will be altered and returned. diff --git a/BDKGeometry.m b/BDKGeometry.m index 7617eaf..803e63b 100644 --- a/BDKGeometry.m +++ b/BDKGeometry.m @@ -3,65 +3,79 @@ * Written by Ben Kreeger. */ -CGRect CGRectAdjustSize(CGRect rect, CGSize size) { +CGRect CGRectSetSize(CGRect rect, CGSize size) { rect.size = size; return rect; } -CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin) { +CGRect CGRectAdjustSize(CGRect rect, CGSize size) { return CGRectSetSize(rect, size); } + +CGRect CGRectSetOrigin(CGRect rect, CGPoint origin) { rect.origin = origin; return rect; } -CGRect CGRectAdjustWidth(CGRect rect, CGFloat width) { +CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin) { return CGRectSetOrigin(rect, origin); } + +CGRect CGRectSetWidth(CGRect rect, CGFloat width) { rect.size.width = width; return rect; } -CGRect CGRectAdjustHeight(CGRect rect, CGFloat height) { +CGRect CGRectAdjustWidth(CGRect rect, CGFloat width) { return CGRectSetWidth(rect, width); } + +CGRect CGRectSetHeight(CGRect rect, CGFloat height) { rect.size.height = height; return rect; } -CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin) { +CGRect CGRectAdjustHeight(CGRect rect, CGFloat height) { return CGRectSetHeight(rect, height); } + +CGRect CGRectSetYOrigin(CGRect rect, CGFloat yOrigin) { rect.origin.y = yOrigin; return rect; } -CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin) { +CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin) { return CGRectSetYOrigin(rect, yOrigin); } + +CGRect CGRectSetXOrigin(CGRect rect, CGFloat xOrigin) { rect.origin.x = xOrigin; return rect; } +CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin) { return CGRectSetXOrigin(rect, xOrigin); } + CGRect CGRectCenterRectInRect(CGRect subRect, CGRect masterRect) { CGPoint origin = CGPointMake((masterRect.size.width - subRect.size.width) / 2.0f, (masterRect.size.height - subRect.size.height) / 2.0f); - return CGRectIntegral(CGRectAdjustOrigin(subRect, origin)); + return CGRectIntegral(CGRectSetOrigin(subRect, origin)); } CGRect CGRectCenterRectInRectHorizontally(CGRect subRect, CGRect masterRect) { - CGPoint origin = CGPointMake((masterRect.size.width - subRect.size.width) / 2.0f, subRect.origin.y); - return CGRectIntegral(CGRectAdjustOrigin(subRect, origin)); + CGPoint origin = CGPointMake((CGRectGetWidth(masterRect) - CGRectGetWidth(subRect)) / 2.0f, subRect.origin.y); + return CGRectIntegral(CGRectSetOrigin(subRect, origin)); } CGRect CGRectCenterRectInRectVertically(CGRect subRect, CGRect masterRect) { - CGPoint origin = CGPointMake(subRect.origin.x, (masterRect.size.height - subRect.size.height) / 2.0f); - return CGRectIntegral(CGRectAdjustOrigin(subRect, origin)); + CGPoint origin = CGPointMake(subRect.origin.x, (CGRectGetHeight(masterRect) - CGRectGetHeight(subRect)) / 2.0f); + return CGRectIntegral(CGRectSetOrigin(subRect, origin)); } CGRect CGRectInsetByPercent(CGRect rect, CGFloat xPercent, CGFloat yPercent) { - return CGRectIntegral(CGRectInset(rect, rect.size.width * xPercent, rect.size.height * yPercent)); + CGRect oldRect = rect; + rect = CGRectSetSize(rect, CGSizeMake(rect.size.width * xPercent, rect.size.height * yPercent)); + return CGRectCenterRectInRect(rect, oldRect); } void CGRectIntegralSizeToFit(UIView *view) { - [view sizeToFit]; + [view sizeToFit]; view.frame = CGRectIntegral(view.frame); } CGSize CGSizeByDoubling(CGSize size) { - return CGSizeMake(size.width * 2.0f, size.height * 2.0f); + return CGSizeMake(size.width * 2.0f, size.height * 2.0f); } CGRect CGRectByDoublingSize(CGRect rect) { - return CGRectAdjustSize(rect, CGSizeByDoubling(rect.size)); + return CGRectSetSize(rect, CGSizeByDoubling(rect.size)); } diff --git a/BDKGeometry.podspec b/BDKGeometry.podspec index b48bab1..4198784 100644 --- a/BDKGeometry.podspec +++ b/BDKGeometry.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'BDKGeometry' - s.version = '1.0.1' + s.version = '1.1.0' s.platform = :ios s.summary = "A set of helper functions I've been using in various XCode projects, abstracted for great good." s.homepage = 'http://github.com/kreeger/BDKGeometry' @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI LICENSE } s.author = { 'Ben Kreeger' => 'ben@kree.gr' } - s.source = { :git => 'https://github.com/kreeger/BDKGeometry.git', :tag => 'v1.0.1' } + s.source = { :git => 'https://github.com/kreeger/BDKGeometry.git', :tag => 'v1.1.0' } s.ios.deployment_target = '5.0' s.source_files = 'BDKGeometry.{h,m}' s.requires_arc = true diff --git a/readme.markdown b/readme.markdown index 980d192..50e0092 100644 --- a/readme.markdown +++ b/readme.markdown @@ -1,3 +1,36 @@ # BDKGeometry -A set of helper functions I've been using in various XCode projects, abstracted for great good! Documentation coming soon. +A set of helper functions I've been using in various XCode projects, abstracted for great good! + +## Getting started + +Really all you should do is check out [the header file][0], but here's a list of the methods available. + +``` objective-c +CGRect CGRectSetSize(CGRect rect, CGSize size); +CGRect CGRectSetOrigin(CGRect rect, CGPoint origin); +CGRect CGRectSetWidth(CGRect rect, CGFloat width); +CGRect CGRectSetHeight(CGRect rect, CGFloat height); +CGRect CGRectSetYOrigin(CGRect rect, CGFloat yOrigin); +CGRect CGRectSetXOrigin(CGRect rect, CGFloat xOrigin); +CGRect CGRectCenterRectInRect(CGRect subRect, CGRect masterRect); +CGRect CGRectCenterRectInRectHorizontally(CGRect subRect, CGRect masterRect); +CGRect CGRectCenterRectInRectVertically(CGRect subRect, CGRect masterRect); +CGRect CGRectInsetByPercent(CGRect rect, CGFloat xPercent, CGFloat yPercent); +void CGRectIntegralSizeToFit(UIView *view); +CGSize CGSizeByDoubling(CGSize size); +CGRect CGRectByDoublingSize(CGRect rect); +``` + +## Installation + +Use [CocoaPods][1], you dingus! + +``` ruby +# Podfile +platform :ios, '5.0' + +pod 'BDKGeometry', '~> 1.1.0' +``` + +[0]: https://github.com/kreeger/BDKGeometry/blob/master/BDKGeometry.h