123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- //
- // KMVerificationTrialViewController.m
- // PDF Reader Pro Edition
- //
- // Created by 王帅 on 2018/5/8.
- //
- #import "KMVerificationTrialViewController.h"
- #import <PDF_Reader_Pro-Swift.h>
- @interface KMVerificationTrialViewController ()
- @property (nonatomic,assign) IBOutlet NSTextField *label;
- @property (nonatomic,assign) IBOutlet NSTextField *sublabel;
- @property (nonatomic,assign) IBOutlet NSView *emailTextFieldView;
- @property (nonatomic,assign) IBOutlet NSTextField *emailTextField;
- @property (nonatomic,assign) IBOutlet NSTextField *emailInvalidLabel;
- @property (nonatomic,assign) IBOutlet NSView *nameTextFieldView;
- @property (nonatomic,assign) IBOutlet NSTextField *nameTextField;
- @property (nonatomic,assign) IBOutlet NSTextField *nameInvalidLabel;
- @property (nonatomic,assign) IBOutlet KMCustomButton *licenseButton;
- @property (nonatomic,assign) IBOutlet KMCustomButton *continueButton;
- @property(nonatomic, assign) IBOutlet NSTextView *accoutTextView;
- @property (assign) IBOutlet NSLayoutConstraint *textViewHeight;
- @property (nonatomic, retain) CALayer *continueButtonLayer;
- @end
- @implementation KMVerificationTrialViewController
- #pragma mark Init Methods
- - (instancetype)init {
- if (self = [super initWithNibName:@"KMVerificationTrialViewController" bundle:nil]) {
-
- }
- return self;
- }
- - (void)dealloc {
-
- }
- #pragma mark View Methods
- - (void)loadView {
- [super loadView];
- // Do view setup here.
- self.emailTextFieldView.wantsLayer = YES;
- self.emailTextFieldView.layer.masksToBounds = YES;
- self.emailTextFieldView.layer.cornerRadius = 4.0;
- self.emailTextFieldView.layer.borderWidth = 1.0;
- self.emailTextFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- self.nameTextFieldView.wantsLayer = YES;
- self.nameTextFieldView.layer.masksToBounds = YES;
- self.nameTextFieldView.layer.cornerRadius = 2.0;
- self.nameTextFieldView.layer.borderWidth = 1.0;
- self.nameTextFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
-
- self.licenseButton.wantsLayer = YES;
- self.licenseButton.layer.masksToBounds = YES;
- self.licenseButton.layer.cornerRadius = 1.0;
- self.continueButton.wantsLayer = YES;
- self.continueButton.layer.masksToBounds = YES;
- self.continueButton.layer.cornerRadius = 1.0;
- self.label.stringValue = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Welcome to", nil), @"PDF Reader Pro"];
- self.sublabel.stringValue = NSLocalizedString(@"Enter your email to activate 7-Day Trial", nil);
-
- [self.emailTextField.cell setPlaceholderString:NSLocalizedString(@"Enter your email", nil)];
- self.emailInvalidLabel.stringValue = NSLocalizedString(@"Please enter valid email", nil);
- [self.nameTextField.cell setPlaceholderString:NSLocalizedString(@"Enter your name", nil)];
- self.nameInvalidLabel.stringValue = NSLocalizedString(@"Please enter valid username", nil);
- self.licenseButton.title = NSLocalizedString(@"Enter License Number", nil);
- self.continueButton.title = NSLocalizedString(@"Activate", nil);
-
- NSString * str1 = NSLocalizedString(@"Privacy Policy",nil);
- NSString * str = [NSString stringWithFormat:NSLocalizedString(@"By clicking the buttons below you confirm that you have read our %@.", nil),str1];
- NSRange range1 = [str rangeOfString:str1];
- NSFont * font = [NSFont systemFontOfSize:11.0];
- NSMutableAttributedString *mastring = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName:font}];
- CGSize size = [self sizeOfString:str witFontSize:font];
- self.textViewHeight.constant = size.height;
-
- [mastring addAttribute:NSForegroundColorAttributeName value:[NSColor textColor] range:NSMakeRange(0, str.length)];
- [mastring addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithRed:0 green:122.0/255.0 blue:1.0 alpha:1.0] range:range1];
-
- NSString *valueString1 = [[NSString stringWithFormat:@"%@",@"https://www.pdfreaderpro.com/privacy-policy"] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
-
- [mastring addAttribute:NSLinkAttributeName value:valueString1 range:range1];
- [self.accoutTextView.textStorage appendAttributedString:mastring];
- [self.accoutTextView setAlignment:NSTextAlignmentCenter];
-
- self.continueButtonLayer = [CALayer layer];
- [self.continueButton.layer addSublayer:self.continueButtonLayer];
- self.continueButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(_continueButton.bounds), CGRectGetHeight(_continueButton.bounds));
- self.continueButtonLayer.backgroundColor = [KMAppearance KMColor_Status_Sel].CGColor;
- self.continueButtonLayer.cornerRadius = 0;
- self.continueButtonLayer.hidden = YES;
- __block KMVerificationTrialViewController *blockSelf = self;
- self.continueButton.mouseMoveCallback = ^(BOOL mouseEntered) {
- if (mouseEntered)
- blockSelf.continueButtonLayer.hidden = NO;
- else
- blockSelf.continueButtonLayer.hidden = YES;
- };
- self.licenseButton.mouseMoveCallback = nil;
-
- [self.label setTextColor:[KMAppearance KMColor_Layout_H0]];
- [self.sublabel setTextColor:[KMAppearance KM_242424_Color75]];
- [self.licenseButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
- [self.continueButton setTitleColor:[NSColor whiteColor]];
- [self.emailTextField setTextColor:[KMAppearance KMColor_Layout_H0]];
- [self.nameTextField setTextColor:[KMAppearance KMColor_Layout_H0]];
- }
- - (NSSize)sizeOfString:(NSString *)string witFontSize:(NSFont *)font
- {
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
- [dictionary setObject:font forKey:NSFontAttributeName];
-
- CGSize size = [string boundingRectWithSize:CGSizeMake(self.accoutTextView.frame.size.width, MAXFLOAT)
- options:NSStringDrawingUsesLineFragmentOrigin
- attributes:dictionary].size;
-
- return size;
- }
- - (void)viewDidAppear {
- [super viewDidAppear];
- [self.nameTextField becomeFirstResponder];
- }
- #pragma mark Button Actions
- - (IBAction)licenseButtonAction:(id)sender {
- if (self.callback) {
- self.callback(0, self.emailTextField.stringValue, self.nameTextField.stringValue);
- }
- }
- - (IBAction)continueButtonAction:(id)sender {
- BOOL isValidate = YES;
- if ([self isValidateEmail:self.emailTextField.stringValue]) {
- self.emailInvalidLabel.hidden = YES;
- self.emailTextFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- } else {
- self.emailInvalidLabel.hidden = NO;
- self.emailTextFieldView.layer.borderColor = self.emailInvalidLabel.textColor.CGColor;
- isValidate = NO;
- }
- if (self.nameTextField.stringValue.length > 0) {
- self.nameInvalidLabel.hidden = YES;
- self.nameTextFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- } else {
- self.nameInvalidLabel.hidden = NO;
- self.nameTextFieldView.layer.borderColor = self.nameInvalidLabel.textColor.CGColor;
- isValidate = NO;
- }
- if (!isValidate) {
- return;
- }
- if (self.callback) {
- self.callback(1, self.emailTextField.stringValue, self.nameTextField.stringValue);
- }
- }
- - (void)setEnabled:(BOOL)enabled {
- self.licenseButton.enabled = enabled;
- self.continueButton.enabled = enabled;
- self.emailTextField.enabled = enabled;
- self.nameTextField.enabled = enabled;
- }
- #pragma mark NSTextFieldDelegate
- - (void)controlTextDidChange:(NSNotification *)notification {
- NSTextField *textField = notification.object;
- if (textField == self.emailTextField) {
- self.emailInvalidLabel.hidden = YES;
- self.emailTextFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- } else if (textField == self.nameTextField) {
- self.nameInvalidLabel.hidden = YES;
- self.nameTextFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
- }
- }
- #pragma mark Private Methods
- - (BOOL)isValidateEmail:(NSString *)email {
- NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
- NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
- return [emailTest evaluateWithObject:email];
- }
- @end
|