KMVerificationTrialViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // KMVerificationTrialViewController.m
  3. // Cisdem PDFMaster
  4. //
  5. // Created by 王帅 on 2018/5/8.
  6. //
  7. #import "KMVerificationTrialViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. @interface KMVerificationTrialViewController ()
  10. @property (nonatomic,assign) IBOutlet NSTextField *label;
  11. @property (nonatomic,assign) IBOutlet KMCustomButton *licenseButton;
  12. @property (nonatomic,assign) IBOutlet KMCustomButton *continueButton;
  13. @property(nonatomic, assign) IBOutlet NSTextView *accoutTextView;
  14. @property (assign) IBOutlet NSLayoutConstraint *textViewHeight;
  15. @property (nonatomic, retain) CALayer *continueButtonLayer;
  16. @end
  17. @implementation KMVerificationTrialViewController
  18. #pragma mark Init Methods
  19. - (instancetype)init {
  20. if (self = [super initWithNibName:@"KMVerificationTrialViewController" bundle:nil]) {
  21. }
  22. return self;
  23. }
  24. - (void)dealloc {
  25. }
  26. #pragma mark View Methods
  27. - (void)loadView {
  28. [super loadView];
  29. // Do view setup here.
  30. self.licenseButton.wantsLayer = YES;
  31. self.licenseButton.layer.masksToBounds = YES;
  32. self.licenseButton.layer.cornerRadius = 1.0;
  33. self.continueButton.wantsLayer = YES;
  34. self.continueButton.layer.masksToBounds = YES;
  35. self.continueButton.layer.cornerRadius = 1.0;
  36. self.label.stringValue = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Welcome to", nil), @"Cisdem PDFMaster"];
  37. self.licenseButton.title = NSLocalizedString(@"Enter License Number", nil);
  38. self.continueButton.title = NSLocalizedString(@"Activate", nil);
  39. // NSString * str1 = NSLocalizedString(@"Privacy Policy",nil);
  40. // NSString * str = [NSString stringWithFormat:NSLocalizedString(@"By clicking the buttons below you confirm that you have read our %@.", nil),str1];
  41. // NSRange range1 = [str rangeOfString:str1];
  42. // NSFont * font = [NSFont systemFontOfSize:11.0];
  43. // NSMutableAttributedString *mastring = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName:font}];
  44. // CGSize size = [self sizeOfString:str witFontSize:font];
  45. // self.textViewHeight.constant = size.height;
  46. //
  47. // [mastring addAttribute:NSForegroundColorAttributeName value:[NSColor textColor] range:NSMakeRange(0, str.length)];
  48. // [mastring addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithRed:0 green:122.0/255.0 blue:1.0 alpha:1.0] range:range1];
  49. //
  50. // NSString *valueString1 = [[NSString stringWithFormat:@"%@",@"https://www.pdfreaderpro.com/privacy-policy"] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
  51. //
  52. // [mastring addAttribute:NSLinkAttributeName value:valueString1 range:range1];
  53. // [self.accoutTextView.textStorage appendAttributedString:mastring];
  54. [self.accoutTextView setAlignment:NSTextAlignmentCenter];
  55. self.continueButtonLayer = [CALayer layer];
  56. [self.continueButton.layer addSublayer:self.continueButtonLayer];
  57. self.continueButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(_continueButton.bounds), CGRectGetHeight(_continueButton.bounds));
  58. self.continueButtonLayer.backgroundColor = [KMAppearance KMColor_Status_Sel].CGColor;
  59. self.continueButtonLayer.cornerRadius = 0;
  60. self.continueButtonLayer.hidden = YES;
  61. __block KMVerificationTrialViewController *blockSelf = self;
  62. self.continueButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  63. if (mouseEntered)
  64. blockSelf.continueButtonLayer.hidden = NO;
  65. else
  66. blockSelf.continueButtonLayer.hidden = YES;
  67. };
  68. self.licenseButton.mouseMoveCallback = nil;
  69. [self.label setTextColor:[KMAppearance KMColor_Layout_H0]];
  70. [self.licenseButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
  71. [self.continueButton setTitleColor:[NSColor whiteColor]];
  72. }
  73. - (NSSize)sizeOfString:(NSString *)string witFontSize:(NSFont *)font
  74. {
  75. NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
  76. [dictionary setObject:font forKey:NSFontAttributeName];
  77. CGSize size = [string boundingRectWithSize:CGSizeMake(self.accoutTextView.frame.size.width, MAXFLOAT)
  78. options:NSStringDrawingUsesLineFragmentOrigin
  79. attributes:dictionary].size;
  80. return size;
  81. }
  82. - (void)viewDidAppear {
  83. [super viewDidAppear];
  84. }
  85. #pragma mark Button Actions
  86. - (IBAction)licenseButtonAction:(id)sender {
  87. if (self.callback) {
  88. self.callback(0, @"", @"");
  89. }
  90. }
  91. - (IBAction)continueButtonAction:(id)sender {
  92. if (self.callback) {
  93. self.callback(1, @"", @"");
  94. }
  95. }
  96. - (void)setEnabled:(BOOL)enabled {
  97. self.licenseButton.enabled = enabled;
  98. self.continueButton.enabled = enabled;
  99. }
  100. #pragma mark NSTextFieldDelegate
  101. - (void)controlTextDidChange:(NSNotification *)notification {
  102. NSTextField *textField = notification.object;
  103. }
  104. #pragma mark Private Methods
  105. - (BOOL)isValidateEmail:(NSString *)email {
  106. NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
  107. NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
  108. return [emailTest evaluateWithObject:email];
  109. }
  110. @end