KMVerificationViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // KMVerificationViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/9.
  6. //
  7. #import "KMVerificationViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "VerificationManager.h"
  10. @interface KMVerificationViewController ()
  11. @property (nonatomic,assign) IBOutlet NSTextField *label;
  12. @property (nonatomic,assign) IBOutlet NSTextField *sublabel;
  13. @property (nonatomic,assign) IBOutlet KMCustomButton *licenseButton;
  14. @property (nonatomic,assign) IBOutlet KMCustomButton *laterButton;
  15. @property (nonatomic,assign) IBOutlet KMCustomButton *buyButton;
  16. @property (nonatomic, retain) CALayer *buyButtonLayer;
  17. @property (assign) IBOutlet NSLayoutConstraint *laterBtnWidthConst;
  18. @property (assign) IBOutlet NSLayoutConstraint *buyBtnWidthConst;
  19. @end
  20. @implementation KMVerificationViewController
  21. #pragma mark Init Methods
  22. - (instancetype)init {
  23. if (self = [super initWithNibName:@"KMVerificationViewController" bundle:nil]) {
  24. }
  25. return self;
  26. }
  27. - (void)dealloc {
  28. }
  29. #pragma mark Setter Methods
  30. - (void)setTitleText:(NSString *)titleText {
  31. _titleText = titleText;
  32. self.label.stringValue = titleText;
  33. }
  34. - (void)setMessageText:(NSString *)messageText {
  35. _messageText = messageText;
  36. self.sublabel.stringValue = messageText;
  37. }
  38. - (void)setButtonText:(NSString *)buttonText {
  39. _buttonText = buttonText;
  40. self.laterButton.title = buttonText;
  41. }
  42. #pragma mark View Methods
  43. - (void)loadView {
  44. [super loadView];
  45. // Do view setup here.
  46. self.view.wantsLayer = YES;
  47. [self.label setTextColor:[KMAppearance KMColor_Layout_H0]];
  48. [self.sublabel setTextColor:[KMAppearance KMColor_Layout_H1]];
  49. self.licenseButton.wantsLayer = YES;
  50. self.licenseButton.layer.masksToBounds = YES;
  51. self.licenseButton.layer.cornerRadius = 1.0;
  52. self.laterButton.wantsLayer = YES;
  53. self.laterButton.layer.masksToBounds = YES;
  54. self.laterButton.layer.cornerRadius = 1.0;
  55. self.buyButton.wantsLayer = YES;
  56. self.buyButton.layer.masksToBounds = YES;
  57. self.buyButton.layer.cornerRadius = 1.0;
  58. self.label.stringValue = self.titleText ? : @"";
  59. self.sublabel.stringValue = self.messageText ? : @"";
  60. self.laterButton.title = self.buttonText ? : NSLocalizedString(@"Later", nil);
  61. self.licenseButton.title = NSLocalizedString(@"Enter License Number", nil);
  62. self.buyButton.title = NSLocalizedString(@"Buy Full Version", nil);
  63. CGSize size = [self.buyButton sizeThatFits:CGSizeMake(MAXFLOAT, self.buyButton.frame.size.width)];
  64. self.buyBtnWidthConst.constant = MAX(size.width + 10, 140);
  65. [self.licenseButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
  66. [self.laterButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
  67. [self.buyButton setTitleColor:[NSColor whiteColor]];
  68. self.buyButtonLayer = [CALayer layer];
  69. [self.buyButton.layer addSublayer:self.buyButtonLayer];
  70. self.buyButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(_buyButton.bounds), CGRectGetHeight(_buyButton.bounds));
  71. self.buyButtonLayer.backgroundColor = [KMAppearance KMColor_Status_Sel].CGColor;
  72. self.buyButtonLayer.cornerRadius = 0;
  73. self.buyButtonLayer.hidden = YES;
  74. __block KMVerificationViewController *blockSelf = self;
  75. self.buyButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  76. if (mouseEntered) {
  77. blockSelf.buyButtonLayer.hidden = NO;
  78. }else {
  79. blockSelf.buyButtonLayer.hidden = YES;
  80. }
  81. };
  82. self.licenseButton.mouseMoveCallback = self.laterButton.mouseMoveCallback = nil;
  83. }
  84. #pragma mark Button Actions
  85. - (IBAction)licenseButtonAction:(id)sender {
  86. if (self.callback) {
  87. self.callback(0);
  88. }
  89. }
  90. - (IBAction)laterButtonAction:(id)sender {
  91. if (self.callback) {
  92. self.callback(1);
  93. }
  94. }
  95. - (IBAction)buyButtonAction:(id)sender {
  96. if (self.callback) {
  97. self.callback(2);
  98. }
  99. }
  100. @end