CPDFKeyboardToolbar.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // CPDFKeyboardToolbar.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFKeyboardToolbar.h"
  13. #if __has_include(<ComPDFKit_Tools/ComPDFKit_Tools.h>)
  14. #import <ComPDFKit_Tools/ComPDFKit_Tools.h>
  15. #else
  16. #import "ComPDFKit_Tools.h"
  17. #endif
  18. @interface CPDFKeyboardToolbar ()
  19. @property (nonatomic, strong) UIButton *doneButton;
  20. @end
  21. @implementation CPDFKeyboardToolbar
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. if (self = [super initWithFrame:frame]) {
  24. self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
  25. [self.doneButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
  26. [self.doneButton setTitleColor:[UIColor colorWithRed:0 green:122.0/255.0 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
  27. [self.doneButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
  28. [self.doneButton sizeToFit];
  29. [self.doneButton addTarget:self action:@selector(buttonItemClick_done:) forControlEvents:UIControlEventTouchUpInside];
  30. [self addSubview:self.doneButton];
  31. self.backgroundColor = [CPDFColorUtils CPDFKeyboardToolbarColor];
  32. }
  33. return self;
  34. }
  35. - (void)layoutSubviews {
  36. if (@available(iOS 11.0, *)) {
  37. self.doneButton.frame = CGRectMake(self.frame.size.width-self.superview.safeAreaInsets.right-60, 0, 50, self.frame.size.height);
  38. } else {
  39. self.doneButton.frame = CGRectMake(self.frame.size.width-70, 0, 50, self.frame.size.height);
  40. }
  41. }
  42. - (void)bindToTextView:(UITextView *)textView {
  43. [textView setInputAccessoryView:self];
  44. }
  45. - (void)bindToTextField:(UITextField *)textField {
  46. [textField setInputAccessoryView:self];
  47. }
  48. - (void)buttonItemClick_done:(id)sender {
  49. if (self.delegate && [self.delegate respondsToSelector:@selector(keyboardShouldDissmiss:)]) {
  50. [self.delegate keyboardShouldDissmiss:self];
  51. }
  52. }
  53. @end