1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // PDFTitleView.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 "PDFTitleView.h"
- @interface PDFTitleView ()
- @property (nonatomic,retain) UILabel *titleLabel;
- @end
- @implementation PDFTitleView
- #pragma mark - Init Methods
- - (instancetype)initWithTitle:(NSString *)title {
- self = [super init];
- if (self){
- _titleLabel = ({
- UILabel *label = [UILabel new];
- label.text = title;
- label.numberOfLines = 2;
- label.lineBreakMode = NSLineBreakByTruncatingMiddle;
- label.textAlignment = NSTextAlignmentCenter;
- label.textColor = [UIColor whiteColor];
- [self addSubview:label];
- label;
- });
-
- self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.6];
- self.layer.cornerRadius = 3;
- self.clipsToBounds = YES;
- }
- return self;
- }
- - (void)dealloc {
- [_titleLabel release];
- [super dealloc];
- }
- #pragma mark - Public Methods
- - (void)showInView:(UIView *)view hideAfter:(NSTimeInterval)delay complete:(void (^)())completeHandle {
- if (self.superview) {
- if ([self.superview isEqual:view]) {
- return;
- } else {
- [self removeFromSuperview];
- }
- }
- CGSize size = [self.titleLabel sizeThatFits:CGSizeMake(view.frame.size.width-54, MAXFLOAT)];
- self.frame = CGRectMake((view.frame.size.width-(size.width+10))/2.0,
- 70, size.width+10, size.height+10);
- self.alpha = 1.0;
- self.titleLabel.frame = CGRectMake(5, 5, self.frame.size.width-10, self.frame.size.height-10);
- self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
- [view addSubview:self];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- [UIView animateWithDuration:0.3 animations:^{
- self.alpha = 0.0;
- } completion:^(BOOL finished) {
- if (completeHandle) {
- completeHandle();
- }
- [self removeFromSuperview];
- }];
- });
- }
- @end
|