// // PDFKTFontNamePopBgView.m // PDFReader // // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved. // // The PDF Reader Sample applications are licensed with a modified BSD license. // Please see License for details. This notice may not be removed from this file. // #import "PDFKTFontNamePopBgView.h" #define CONTENT_INSET 3.0 #define CAP_INSET 20.0 #define ARROW_BASE 42.0 #define ARROW_HEIGHT 16.0 @interface PDFKTFontNamePopBgView () { UIImageView *_borderImageView; UIImageView *_arrowView; CGFloat _arrowOffset; UIPopoverArrowDirection _arrowDirection; } @end @implementation PDFKTFontNamePopBgView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; self.layer.shadowOffset = CGSizeZero; self.layer.shadowColor = [[UIColor clearColor] CGColor]; self.layer.cornerRadius = 0.0; _borderImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"text_bg"]]; _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"text_arrow_bg"]]; [self addSubview:_borderImageView]; [self addSubview:_arrowView]; } return self; } - (CGFloat) arrowOffset { return _arrowOffset; } - (void) setArrowOffset:(CGFloat)arrowOffset { _arrowOffset = arrowOffset; } - (UIPopoverArrowDirection)arrowDirection { return _arrowDirection; } - (void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection { _arrowDirection = arrowDirection; } +(UIEdgeInsets)contentViewInsets { return UIEdgeInsetsMake(CONTENT_INSET, CONTENT_INSET, CONTENT_INSET, CONTENT_INSET); } +(CGFloat)arrowHeight { return ARROW_HEIGHT; } +(CGFloat)arrowBase { return ARROW_BASE; } + (BOOL)wantsDefaultContentAppearance { return NO; } - (void)layoutSubviews { [super layoutSubviews]; CGFloat _height = self.frame.size.height; CGFloat _width = self.frame.size.width; CGFloat _left = 0.0; CGFloat _top = 0.0; CGFloat _coordinate = 0.0; CGAffineTransform _rotation = CGAffineTransformIdentity; switch (self.arrowDirection) { case UIPopoverArrowDirectionUp: _top += ARROW_HEIGHT; _height -= ARROW_HEIGHT; _coordinate = ((self.frame.size.width / 2) + self.arrowOffset) - (ARROW_BASE/2); _arrowView.frame = CGRectMake(_coordinate, 0, ARROW_BASE, ARROW_HEIGHT); _rotation = CGAffineTransformMakeRotation( M_PI ); break; case UIPopoverArrowDirectionDown: _height -= ARROW_HEIGHT; _coordinate = ((self.frame.size.width / 2) + self.arrowOffset) - (ARROW_BASE/2); _arrowView.frame = CGRectMake(_coordinate, _height, ARROW_BASE, ARROW_HEIGHT); break; case UIPopoverArrowDirectionLeft: _left += ARROW_BASE; _width -= ARROW_BASE; _coordinate = ((self.frame.size.height / 2) + self.arrowOffset) - (ARROW_HEIGHT/2); _arrowView.frame = CGRectMake(0, _coordinate, ARROW_BASE, ARROW_HEIGHT); _rotation = CGAffineTransformMakeRotation( M_PI_2 ); break; case UIPopoverArrowDirectionRight: _width -= ARROW_BASE; _coordinate = ((self.frame.size.height / 2) + self.arrowOffset)- (ARROW_HEIGHT/2); _arrowView.frame = CGRectMake(_width, _coordinate, ARROW_BASE, ARROW_HEIGHT); _rotation = CGAffineTransformMakeRotation( -M_PI_2 ); break; } _borderImageView.frame = CGRectMake(_left, _top, _width, _height); [_arrowView setTransform:_rotation]; } - (void)dealloc { [_borderImageView release]; [_arrowView release]; [super dealloc]; } @end