Permalink
Browse files

add rounding to all centering apis; add centerVerticallyInRect(() fun…

…ction
  • Loading branch information...
1 parent 298978b commit 120718c549bbc9888237861e4a8b8bec146efb29 @ettore committed Dec 3, 2013
Showing with 32 additions and 17 deletions.
  1. +6 −1 categories/CLCGUIViewCategory.h
  2. +26 −16 categories/CLCGUIViewCategory.m
@@ -47,10 +47,15 @@
-(void)centerVerticallyWithOffset:(CGFloat)offset;
/*!
- * Centers this view in the given rect.
+ * Centers this view horizontally in the given rect.
*/
-(void)centerHorizontallyInRect:(CGRect)rect;
+/*!
+ * Centers this view vertically in the given rect.
+ */
+-(void)centerVerticallyInRect:(CGRect)rect;
+
-(void)resizeHeightForText:(NSString*)txt font:(UIFont*)font;
-(UIView*)findFirstResponder;
@@ -26,50 +26,60 @@
//
+#import "tgmath.h"
+
#import "CLCGUIViewCategory.h"
#import "clcg_gfx.h"
+
@implementation UIView (Candygirl)
--(void)centerVertically
+-(void)centerHorizontally
{
- [self centerVerticallyWithOffset:0];
+ [self centerHorizontallyWithOffset:0];
}
--(void)centerVerticallyWithOffset:(CGFloat)offset
+-(void)centerHorizontallyWithOffset:(CGFloat)offset
{
CGSize sz;
- CGFloat y;
-
+ CGFloat x;
+
sz = [[self superview] frame].size;
- y = (sz.height - [self h])/2 + offset;
- [self setY:y];
+ x = (sz.width - [self w])/2 + offset;
+ [self setX:round(x)];
}
--(void)centerHorizontally
+-(void)centerHorizontallyInRect:(CGRect)rect
{
- [self centerHorizontallyWithOffset:0];
+ CGFloat x = (rect.size.width - [self w])/2;
+ [self setX:round(rect.origin.x + x)];
}
--(void)centerHorizontallyWithOffset:(CGFloat)offset
+-(void)centerVertically
+{
+ [self centerVerticallyWithOffset:0];
+}
+
+
+-(void)centerVerticallyWithOffset:(CGFloat)offset
{
CGSize sz;
- CGFloat x;
+ CGFloat y;
sz = [[self superview] frame].size;
- x = (sz.width - [self w])/2 + offset;
- [self setX:x];
+ y = (sz.height - [self h])/2 + offset;
+ [self setY:round(y)];
}
--(void)centerHorizontallyInRect:(CGRect)rect
+-(void)centerVerticallyInRect:(CGRect)rect
{
- CGFloat x = (rect.size.width - [self w])/2;
- [self setX:(rect.origin.x + x)];
+ CGFloat y = (rect.size.height - [self h])/2;
+ [self setY:round(rect.origin.y + y)];
}

0 comments on commit 120718c

Please sign in to comment.