123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // 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
|