// // KMVerificationTrialViewController.m // Cisdem PDFMaster // // Created by 王帅 on 2018/5/8. // #import "KMVerificationTrialViewController.h" #import @interface KMVerificationTrialViewController () @property (nonatomic,assign) IBOutlet NSTextField *label; @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.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), @"Cisdem PDFMaster"]; 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.licenseButton setTitleColor:[KMAppearance KMColor_Layout_H0]]; [self.continueButton setTitleColor:[NSColor whiteColor]]; } - (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]; } #pragma mark Button Actions - (IBAction)licenseButtonAction:(id)sender { if (self.callback) { self.callback(0, @"", @""); } } - (IBAction)continueButtonAction:(id)sender { if (self.callback) { self.callback(1, @"", @""); } } - (void)setEnabled:(BOOL)enabled { self.licenseButton.enabled = enabled; self.continueButton.enabled = enabled; } #pragma mark NSTextFieldDelegate - (void)controlTextDidChange:(NSNotification *)notification { NSTextField *textField = notification.object; } #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