Skip to content

Commit

Permalink
Adding new helpers and a category.
Browse files Browse the repository at this point in the history
  • Loading branch information
kreeger committed Feb 21, 2013
1 parent ce55284 commit e23a097
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
3 changes: 3 additions & 0 deletions BDKGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Written by Ben Kreeger.
*/

#import <UIKit/UIKit.h>
#import "UIView+BDKGeometry.h"

/** Gives a rect a new size.
* @param rect the rect on which to operate.
* @param size a new CGSize to assign to `rect`.
Expand Down
6 changes: 3 additions & 3 deletions BDKGeometry.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BDKGeometry'
s.version = '1.1.0'
s.version = '1.2.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'
Expand All @@ -17,8 +17,8 @@ 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.1.0' }
s.source = { :git => 'https://github.com/kreeger/BDKGeometry.git', :tag => 'v1.2.0' }
s.ios.deployment_target = '5.0'
s.source_files = 'BDKGeometry.{h,m}'
s.source_files = ['BDKGeometry.{h,m}', 'UIView+BDKGeometry.{h,m}']
s.requires_arc = true
end
48 changes: 48 additions & 0 deletions UIView+BDKGeometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#import <UIKit/UIKit.h>

/** A set of geometry convenience methods for UIView.
*/
@interface UIView (BDKGeometry)

/** Origin modification helper.
* @param origin the origin to use.
*/
- (void)setOrigin:(CGPoint)origin;

/** X-origin modification helper.
* @param xOrigin the x-origin to use.
*/
- (void)setXOrigin:(CGFloat)xOrigin;

/** Y-origin modification helper.
* @param yOrigin the y-origin to use.
*/
- (void)setYOrigin:(CGFloat)yOrigin;

/** Size modification helper.
* @param size the size to use.
*/
- (void)setSize:(CGSize)size;

/** Width modification helper.
* @param width the width to use.
*/
- (void)setWidth:(CGFloat)width;

/** Height modification helper.
* @param height the height to use.
*/
- (void)setHeight:(CGFloat)height;

/** Positions a view directly beneath another view.
* @param view the view to position this view below.
*/
- (void)positionViewBelowView:(UIView *)view;

/** Positions a view directly beneath another view, with padding.
* @param view the view to position this view below.
* @param padding the padding to put between.
*/
- (void)positionViewBelowView:(UIView *)view padding:(CGFloat)padding;

@end
38 changes: 38 additions & 0 deletions UIView+BDKGeometry.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#import "UIView+BDKGeometry.h"
#import "BDKGeometry.h"

@implementation UIView (BDKGeometry)

- (void)setOrigin:(CGPoint)origin {
self.frame = CGRectSetOrigin(self.frame, origin);
}

- (void)setXOrigin:(CGFloat)xOrigin {
self.frame = CGRectSetXOrigin(self.frame, xOrigin);
}

- (void)setYOrigin:(CGFloat)yOrigin {
self.frame = CGRectSetYOrigin(self.frame, yOrigin);
}

- (void)setSize:(CGSize)size {
self.frame = CGRectSetSize(self.frame, size);
}

- (void)setWidth:(CGFloat)width {
self.frame = CGRectSetWidth(self.frame, width);
}

- (void)setHeight:(CGFloat)height {
self.frame = CGRectSetHeight(self.frame, height);
}

- (void)positionViewBelowView:(UIView *)view {
[self positionViewBelowView:view padding:0];
}

- (void)positionViewBelowView:(UIView *)view padding:(CGFloat)padding {
[self setYOrigin:CGRectGetMaxY(view.frame) + padding];
}

@end

0 comments on commit e23a097

Please sign in to comment.