Skip to content

Instantly share code, notes, and snippets.

Andrey Isaev siberianisaev

View GitHub Profile
@siberianisaev
siberianisaev / NativeWebView.swift
Created Apr 22, 2020 — forked from maxcampolo/NativeWebView.swift
WKWebView setup to make a web page adopt native behavior.
View NativeWebView.swift
import WebKit
class NativeWebViewController: UIViewController {
let viewportScriptString = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); meta.setAttribute('initial-scale', '1.0'); meta.setAttribute('maximum-scale', '1.0'); meta.setAttribute('minimum-scale', '1.0'); meta.setAttribute('user-scalable', 'no'); document.getElementsByTagName('head')[0].appendChild(meta);"
let disableSelectionScriptString = "document.documentElement.style.webkitUserSelect='none';"
let disableCalloutScriptString = "document.documentElement.style.webkitTouchCallout='none';"
override func viewDidLoad() {
// 1 - Make user scripts for injection
@siberianisaev
siberianisaev / html-table.swift
Last active Jan 14, 2016
Replace HTML table with spaces and new lines
View html-table.swift
extension UIFont {
func sizeOfString(string: NSString, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: self], context: nil).size
}
}
extension String {
@siberianisaev
siberianisaev / NSString+Email.swift
Created Dec 22, 2014
Email address validation (swift version)
View NSString+Email.swift
import Foundation
extension NSString {
/**
http://stackoverflow.com/questions/800123/what-are-best-practices-for-validating-email-addresses-in-objective-c-for-ios-2
RFC 2822 http://tools.ietf.org/html/rfc2822
*/
func isEmail() -> Bool {
let sRegex = "(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
@siberianisaev
siberianisaev / UINavigationBar+Height.swift
Last active Oct 30, 2019
Change height of UINavigationBar
View UINavigationBar+Height.swift
import Foundation
private var AssociatedObjectHandle: UInt8 = 0
extension UINavigationBar {
var height: CGFloat {
get {
if let h = objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat {
View ExceptionHandler.h
#import <Foundation/Foundation.h>
@interface ExceptionHandler : NSObject
+ (void)startHandleExceptions;
@end
View NSString+URLEncoding.h
#import <Foundation/Foundation.h>
@interface NSString (URLEncoding)
- (NSString *)urlEncodedString;
- (NSString *)stringByDecodingURLFormat;
@end
@siberianisaev
siberianisaev / singleton
Created Feb 13, 2014
Singleton snippet for Xcode 5
View singleton
+ (<#Class name#> *)<#Singleton method#>
{
static <#Class name#> *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[<#Class name#> alloc] init];
});
return sharedInstance;
}
You can’t perform that action at this time.