Permalink
Browse files

Left and right border

  • Loading branch information...
1 parent dbe53cd commit ab487736004f504b74a1dd386f265cfa86ef03ae @soffes committed Jun 3, 2013
Showing with 109 additions and 30 deletions.
  1. +39 −16 SSToolkit/SSBorderedView.h
  2. +70 −14 SSToolkit/SSBorderedView.m
View
@@ -11,41 +11,64 @@
*/
@interface SSBorderedView : UIView
-///-----------------------------
-/// @name Drawing the Top Border
-///-----------------------------
+///--------------------------
+/// @name Drawing the Borders
+///--------------------------
/**
The top border color. The default is `nil`.
-
- @see bottomBorderColor
+
+ @see topInsetColor
*/
@property (nonatomic, strong) UIColor *topBorderColor;
/**
The top inset color. The default is `nil`.
-
- @see bottomInsetColor
+
+ @see topBorderColor
*/
@property (nonatomic, strong) UIColor *topInsetColor;
+/**
+ The right border color. The default is `nil`.
-///--------------------------------
-/// @name Drawing the Bottom Border
-///--------------------------------
+ @see rightInsetColor
+ */
+@property (nonatomic, strong) UIColor *rightBorderColor;
/**
- The bottom inset color. The default is `nil`.
-
- @see topInsetColor
+ The right inset color. The default is `nil`.
+
+ @see rightBorderColor
*/
-@property (nonatomic, strong) UIColor *bottomInsetColor;
+@property (nonatomic, strong) UIColor *rightInsetColor;
/**
The bottom border color. The default is `nil`.
-
- @see topBorderColor
+
+ @see bottomInsetColor
*/
@property (nonatomic, strong) UIColor *bottomBorderColor;
+/**
+ The bottom inset color. The default is `nil`.
+
+ @see bottomBorderColor
+ */
+@property (nonatomic, strong) UIColor *bottomInsetColor;
+
+/**
+ The left border color. The default is `nil`.
+
+ @see leftInsetColor
+ */
+@property (nonatomic, strong) UIColor *leftBorderColor;
+
+/**
+ The left inset color. The default is `nil`.
+
+ @see leftBorderColor
+ */
+@property (nonatomic, strong) UIColor *leftInsetColor;
+
@end
View
@@ -13,12 +13,6 @@ @implementation SSBorderedView
#pragma mark - Accessors
-@synthesize topBorderColor = _topBorderColor;
-@synthesize topInsetColor = _topInsetColor;
-@synthesize bottomInsetColor = _bottomInsetColor;
-@synthesize bottomBorderColor = _bottomBorderColor;
-
-
- (void)setTopBorderColor:(UIColor *)topBorderColor {
_topBorderColor = topBorderColor;
[self setNeedsDisplay];
@@ -31,14 +25,38 @@ - (void)setTopInsetColor:(UIColor *)topInsetColor {
}
-- (void)setBottomInsetColor:(UIColor *)bottomInsetColor {
- _bottomInsetColor = bottomInsetColor;
+- (void)setRightBorderColor:(UIColor *)rightBorderColor {
+ _rightBorderColor = rightBorderColor;
+ [self setNeedsDisplay];
+}
+
+
+- (void)setRightInsetColor:(UIColor *)rightInsetColor {
+ _rightInsetColor = rightInsetColor;
[self setNeedsDisplay];
}
- (void)setBottomBorderColor:(UIColor *)bottomBorderColor {
- _bottomBorderColor = bottomBorderColor;
+ _bottomBorderColor = bottomBorderColor;
+ [self setNeedsDisplay];
+}
+
+
+- (void)setBottomInsetColor:(UIColor *)bottomInsetColor {
+ _bottomInsetColor = bottomInsetColor;
+ [self setNeedsDisplay];
+}
+
+
+- (void)setLeftBorderColor:(UIColor *)leftBorderColor {
+ _bottomBorderColor = leftBorderColor;
+ [self setNeedsDisplay];
+}
+
+
+- (void)setLeftInsetColor:(UIColor *)leftInsetColor {
+ _leftInsetColor = leftInsetColor;
[self setNeedsDisplay];
}
@@ -56,32 +74,70 @@ - (id)initWithFrame:(CGRect)frame {
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToRect(context, rect);
-
+
CGSize size = rect.size;
-
+
+ // Top
if (_topBorderColor) {
// Top inset
if (_topInsetColor) {
CGContextSetFillColorWithColor(context, _topInsetColor.CGColor);
CGContextFillRect(context, CGRectMake(0.0f, 1.0f, size.width, 1.0f));
}
-
+
// Top border
CGContextSetFillColorWithColor(context, _topBorderColor.CGColor);
CGContextFillRect(context, CGRectMake(0.0f, 0.0f, size.width, 1.0f));
}
-
+
+ CGFloat sideY = _topBorderColor ? 1.0f : 0.0f;
+ CGFloat sideHeight = size.height;
+ if (_topBorderColor) {
+ sideHeight -= 1.0f;
+ }
+
+ if (_bottomBorderColor) {
+ sideHeight -= 1.0f;
+ }
+
+ // Right
+ if (_rightBorderColor) {
+ // Right inset
+ if (_rightInsetColor) {
+ CGContextSetFillColorWithColor(context, _rightInsetColor.CGColor);
+ CGContextFillRect(context, CGRectMake(size.width - 2.0f, sideY, 1.0f, sideHeight));
+ }
+
+ // Right border
+ CGContextSetFillColorWithColor(context, _rightBorderColor.CGColor);
+ CGContextFillRect(context, CGRectMake(size.width - 1.0f, sideY, 1.0f, sideHeight));
+ }
+
+ // Bottom
if (_bottomBorderColor) {
// Bottom inset
if (_bottomInsetColor) {
CGContextSetFillColorWithColor(context, _bottomInsetColor.CGColor);
CGContextFillRect(context, CGRectMake(0.0f, rect.size.height - 2.0f, size.width, 1.0f));
}
-
+
// Bottom border
CGContextSetFillColorWithColor(context, _bottomBorderColor.CGColor);
CGContextFillRect(context, CGRectMake(0.0f, rect.size.height - 1.0f, size.width, 1.0f));
}
+
+ // Left
+ if (_leftBorderColor) {
+ // Left inset
+ if (_leftInsetColor) {
+ CGContextSetFillColorWithColor(context, _leftInsetColor.CGColor);
+ CGContextFillRect(context, CGRectMake(1.0f, sideY, 1.0f, sideHeight));
+ }
+
+ // Left border
+ CGContextSetFillColorWithColor(context, _leftBorderColor.CGColor);
+ CGContextFillRect(context, CGRectMake(0.0f, sideY, 1.0f, sideHeight));
+ }
}
@end

0 comments on commit ab48773

Please sign in to comment.