12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // CPDFTextPreview.m
- // PDFViewer
- //
- // Created by kdan on 2022/11/18.
- //
- #import "CPDFTextPreview.h"
- #import "Masonry.h"
- BOOL gTextPreviewIsFirstLayout = YES;
- @implementation CPDFTextPreview
- - (instancetype)initWithFrame:(CGRect)frame
- {
- if (self = [super initWithFrame:frame]) {
- _watermarkLabel = [[UILabel alloc] init];
- _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _documentView = [[UIImageView alloc] init];
-
- [self addSubview:_documentView];
- [_documentView addSubview:_watermarkLabel];
- [_watermarkLabel addSubview:_rotationBtn];
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- _watermarkLabel.layer.borderWidth = 1;
- _watermarkLabel.layer.borderColor = UIColor.blueColor.CGColor;
- [_watermarkLabel sizeToFit];
- if (gTextPreviewIsFirstLayout) {
- CGRect frame = _watermarkLabel.frame;
- frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _watermarkLabel.frame.size.width / 2, _documentView.bounds.size.height / 2 - _watermarkLabel.frame.size.height / 2);
- _watermarkLabel.frame = frame;
- gTextPreviewIsFirstLayout = NO;
- }
- _rotationBtn.layer.cornerRadius = 10;
- _rotationBtn.layer.masksToBounds = YES;
- _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
- [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
-
- [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(_watermarkLabel.mas_bottom).offset(-10);
- make.width.equalTo(@20);
- make.height.equalTo(@20);
- make.left.equalTo(_watermarkLabel.mas_right).offset(-10);
- }];
- }
- @end
|