Skip to content

Commit

Permalink
Renamed NGSPopoverArrowPosition to NGSPopoverArrowDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
PauliusVindzigelskis committed Oct 19, 2017
1 parent beac387 commit e0f08bd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions NGSPopoverViewExample/NGSPopoverViewExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ -(void)viewDidLoad

- (NGSPopoverView*) popoverViewWithCornerRadius:(CGFloat)cornerRadius
{
NGSPopoverView* popover = [[NGSPopoverView alloc] initWithCornerRadius:cornerRadius direction:NGSPopoverArrowPositionAutomatic arrowSize:CGSizeMake(20.f, 20.f)];
NGSPopoverView* popover = [[NGSPopoverView alloc] initWithCornerRadius:cornerRadius direction:NGSPopoverArrowDirectionAutomatic arrowSize:CGSizeMake(20.f, 20.f)];


UILabel *label = [[UILabel alloc] init];
Expand Down Expand Up @@ -88,7 +88,7 @@ - (IBAction)fithPressed:(id)sender
popover.outsideColor = [UIColor clearColor];
popover.tintColor = [UIColor colorWithWhite:0 alpha:0.5f];

popover.arrowDirection = NGSPopoverArrowPositionBottom;
popover.arrowDirection = NGSPopoverArrowDirectionBottom;

[popover showFromView:sender animated:YES];
}
Expand Down
18 changes: 9 additions & 9 deletions Pod/Classes/NGSPopoverView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, NGSPopoverArrowPosition)
typedef NS_ENUM(NSInteger, NGSPopoverArrowDirection)
{
NGSPopoverArrowPositionAutomatic,
NGSPopoverArrowPositionBottom,
NGSPopoverArrowPositionLeft,
NGSPopoverArrowPositionTop,
NGSPopoverArrowPositionRight,
NGSPopoverArrowPositionCount
NGSPopoverArrowDirectionAutomatic,
NGSPopoverArrowDirectionBottom,
NGSPopoverArrowDirectionLeft,
NGSPopoverArrowDirectionTop,
NGSPopoverArrowDirectionRight,
NGSPopoverArrowDirectionCount
};

@class NGSPopoverView;
Expand All @@ -40,7 +40,7 @@ IB_DESIGNABLE
/*!
* @brief Arrow direction to draw - left, right, top or bottom
*/
@property (nonatomic, assign) IBInspectable NGSPopoverArrowPosition arrowDirection;
@property (nonatomic, assign) IBInspectable NGSPopoverArrowDirection arrowDirection;

/*!
* @brief Arrow size in dimensions. How it will look like depends on arow direction.
Expand Down Expand Up @@ -98,7 +98,7 @@ IB_DESIGNABLE
* @param arrowSize Arrow dimensions in CGSize. If not square, look differs for vertical and horizontal arrow.
*/
-(instancetype)initWithCornerRadius:(CGFloat)cornerRadius
direction:(NGSPopoverArrowPosition)arrowDirection
direction:(NGSPopoverArrowDirection)arrowDirection
arrowSize:(CGSize)arrowSize;
/*!
* @brief Don't add content view manually! This method adds it with automatic position calculation according to arrow size and position.
Expand Down
58 changes: 29 additions & 29 deletions Pod/Classes/NGSPopoverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ - (instancetype) init
} return self;
}

-(instancetype)initWithCornerRadius:(CGFloat)corner direction:(NGSPopoverArrowPosition)direction arrowSize:(CGSize)arrSize
-(instancetype)initWithCornerRadius:(CGFloat)corner direction:(NGSPopoverArrowDirection)direction arrowSize:(CGSize)arrSize
{
if (self = [self init])
{
NSAssert((direction >=0 && direction < NGSPopoverArrowPositionCount), @"");
NSAssert((direction >=0 && direction < NGSPopoverArrowDirectionCount), @"");
_arrowDirection = direction;
_cornerRadius = corner;
_arrowSize = arrSize;
Expand Down Expand Up @@ -81,11 +81,11 @@ -(void)setContentView:(UIView *)contentView withInsets:(UIEdgeInsets)margins
}
}

-(void)setArrowDirection:(NGSPopoverArrowPosition)arrowDirection
-(void)setArrowDirection:(NGSPopoverArrowDirection)arrowDirection
{
NGSPopoverArrowPosition oldDirection = _arrowDirection;
NGSPopoverArrowDirection oldDirection = _arrowDirection;

NSAssert((arrowDirection >=0 && arrowDirection < NGSPopoverArrowPositionCount), @"");
NSAssert((arrowDirection >=0 && arrowDirection < NGSPopoverArrowDirectionCount), @"");
_arrowDirection = arrowDirection;
self.isArrowDirectionChanged = YES;

Expand All @@ -107,10 +107,10 @@ - (void) switchArrowSizeValues

}

- (BOOL) isDirectionHorizontal:(NGSPopoverArrowPosition)position
- (BOOL) isDirectionHorizontal:(NGSPopoverArrowDirection)position
{
return (position == NGSPopoverArrowPositionLeft
|| position == NGSPopoverArrowPositionRight);
return (position == NGSPopoverArrowDirectionLeft
|| position == NGSPopoverArrowDirectionRight);
}

-(UIColor *)tintColor
Expand Down Expand Up @@ -148,20 +148,20 @@ - (UIEdgeInsets) edgeInsets
{

UIEdgeInsets insets = UIEdgeInsetsZero;
switch ((NGSPopoverArrowPosition)self.arrowDirection) {
case NGSPopoverArrowPositionBottom:
switch ((NGSPopoverArrowDirection)self.arrowDirection) {
case NGSPopoverArrowDirectionBottom:
{
insets.bottom = self.arrowSize.height;
} break;
case NGSPopoverArrowPositionLeft:
case NGSPopoverArrowDirectionLeft:
{
insets.left = self.arrowSize.width;
} break;
case NGSPopoverArrowPositionTop:
case NGSPopoverArrowDirectionTop:
{
insets.top = self.arrowSize.height;
} break;
case NGSPopoverArrowPositionRight:
case NGSPopoverArrowDirectionRight:
{
insets.right = self.arrowSize.width;
} break;
Expand Down Expand Up @@ -248,8 +248,8 @@ - (void) drawArrow
CGFloat arrowWidth = _arrowSize.width;
CGFloat arrowHeight = _arrowSize.height;

switch ((NGSPopoverArrowPosition)self.arrowDirection) {
case NGSPopoverArrowPositionBottom:
switch ((NGSPopoverArrowDirection)self.arrowDirection) {
case NGSPopoverArrowDirectionBottom:
{
startPosition.y = self.frame.size.height;

Expand All @@ -259,7 +259,7 @@ - (void) drawArrow

insets.bottom = arrowHeight;
} break;
case NGSPopoverArrowPositionLeft:
case NGSPopoverArrowDirectionLeft:
{
startPosition.x = 0.f;

Expand All @@ -270,7 +270,7 @@ - (void) drawArrow
insets.left = arrowWidth;
} break;
default:
case NGSPopoverArrowPositionTop:
case NGSPopoverArrowDirectionTop:
{
startPosition.y = 0.f;

Expand All @@ -280,7 +280,7 @@ - (void) drawArrow

insets.top = arrowHeight;
} break;
case NGSPopoverArrowPositionRight:
case NGSPopoverArrowDirectionRight:
{
startPosition.x = self.frame.size.width;

Expand Down Expand Up @@ -345,10 +345,10 @@ -(void)layoutSubviews

- (BOOL) isArrowVertical
{
return (self.arrowDirection == NGSPopoverArrowPositionTop || self.arrowDirection == NGSPopoverArrowPositionBottom);
return (self.arrowDirection == NGSPopoverArrowDirectionTop || self.arrowDirection == NGSPopoverArrowDirectionBottom);
}

-(NGSPopoverArrowPosition) arrowDirectionForView:(UIView*)view superView:(UIView*)superview
-(NGSPopoverArrowDirection) arrowDirectionForView:(UIView*)view superView:(UIView*)superview
{
//detect arrow direction
CGRect frame = [view.superview convertRect:view.frame toView:superview];
Expand All @@ -359,14 +359,14 @@ -(NGSPopoverArrowPosition) arrowDirectionForView:(UIView*)view superView:(UIView

CGFloat maxVerticalValue = MAX(bottomSpace, topSpace);
CGFloat maxHorizontalValue = MAX(leftSpace, rightSpace);
NGSPopoverArrowPosition direction;
NGSPopoverArrowDirection direction;
if (maxHorizontalValue > maxVerticalValue)
{
//horizontal it is!
direction = leftSpace > rightSpace ? NGSPopoverArrowPositionRight : NGSPopoverArrowPositionLeft;
direction = leftSpace > rightSpace ? NGSPopoverArrowDirectionRight : NGSPopoverArrowDirectionLeft;
} else {
//vertical it is!
direction = topSpace > bottomSpace ? NGSPopoverArrowPositionBottom : NGSPopoverArrowPositionTop;
direction = topSpace > bottomSpace ? NGSPopoverArrowDirectionBottom : NGSPopoverArrowDirectionTop;
}

return direction;
Expand All @@ -380,7 +380,7 @@ -(void)showFromView:(UIView *)anchorView animated:(BOOL)animated
self.fromView = anchorView;
UIView *superview = anchorView.window;

if (self.arrowDirection == NGSPopoverArrowPositionAutomatic)
if (self.arrowDirection == NGSPopoverArrowDirectionAutomatic)
{
self.arrowDirection = [self arrowDirectionForView:anchorView superView:superview];
}
Expand Down Expand Up @@ -438,30 +438,30 @@ -(void)showFromView:(UIView *)anchorView animated:(BOOL)animated
CGFloat offset = 5.f;
NSLayoutConstraint *first;
NSLayoutConstraint *second;
switch ((NGSPopoverArrowPosition)self.arrowDirection) {
switch ((NGSPopoverArrowDirection)self.arrowDirection) {

case NGSPopoverArrowPositionBottom:
case NGSPopoverArrowDirectionBottom:
{
first = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.f];
second = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0f constant:offset];
} break;

default:
case NGSPopoverArrowPositionTop:
case NGSPopoverArrowDirectionTop:
{
first = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.f];
second = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0f constant:-offset];
} break;

case NGSPopoverArrowPositionLeft:
case NGSPopoverArrowDirectionLeft:
{
first = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0f constant:-offset];
second = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.f];

} break;


case NGSPopoverArrowPositionRight:
case NGSPopoverArrowDirectionRight:
{
first = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0f constant:offset];
second = [NSLayoutConstraint constraintWithItem:anchorView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.f];
Expand Down

0 comments on commit e0f08bd

Please sign in to comment.