Skip to content

Instantly share code, notes, and snippets.

View KanshuYokoo's full-sized avatar

kkaannnssshh KanshuYokoo

View GitHub Profile
@KanshuYokoo
KanshuYokoo / open view storyboard
Created March 27, 2019 18:45
ios, Xocde, swift, Open View from storyboard programatically on AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Assume there are firstView and SecondView in the Main.storyboard
// open SecondView
window = UIWindow(frame: UIScreen.main.bounds)
let storyboad: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyboad.instantiateViewController(withIdentifier: "SecondView") as UIViewController
window!.rootViewController = newViewController
window!.makeKeyAndVisible()
return true
}
@KanshuYokoo
KanshuYokoo / checkEmailvalidation
Created March 19, 2019 14:20
regx to check email text using NSPredicate. ios, swift
let emailRegX = "[A-Z0-9a-z?./_%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let emailTest = NSPredicate.init(format: "SELF MATCHES %@", emailRegX)
let isEmail = emailTest.evaluate(with: "[email protected]")
@KanshuYokoo
KanshuYokoo / CustomButtonWithRadius
Created March 13, 2019 17:55
ios customise UIButton enable border radius
import UIKit
@IBDesignable class ButtonRadius: UIButton {
@IBInspectable var cornerRadius: CGFloat = 0.0 {
didSet{
self.layer.cornerRadius = cornerRadius
}
}
@KanshuYokoo
KanshuYokoo / CustomBorderView
Created March 13, 2019 17:49
ios custom BorderView
import UIKit
@IBDesignable class CustomBorderView: UIView {
@IBInspectable var cornerRadius: CGFloat = 0{
didSet{
self.layer.cornerRadius = cornerRadius
}
}
@KanshuYokoo
KanshuYokoo / gist:a30f7f923ceade4c7b3553f1287a1c85
Created February 25, 2019 15:11
Reac-Native: how to place icon images vertical and horizontal centre over background
const { width, height } = Dimensions.get('window')
const sizeStyle = {
width: width,
height: height
}
const styleImage = {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
@KanshuYokoo
KanshuYokoo / react Native check iphoneX
Created February 21, 2019 14:11
ios react native iphonex
import { Dimensions, Platform } from 'react-native';
export function isIphoneX() {
const dimWindow = Dimensions.get('window')
return (
Platform.OS === 'ios' &&
(isIPhoneXSize(dimWindow) || isIPhoneXRMAXSize(dimWindow))
)
}
export function isIPhoneXSize(window) {
@KanshuYokoo
KanshuYokoo / different props types
Created February 8, 2019 07:50
React.js give multiple PropsTypes.
Style: PropTypes.oneOfType(
[
PropTypes.number,
PropTypes.object,
PropTypes.array
]
)
@KanshuYokoo
KanshuYokoo / isEmpty
Created October 20, 2018 14:39
empty check of UITextField, iOS Swift
IBOutlet weak var field1: UITextField!
if(field1.text?.isEmpty ?? true) {
// field is empty
return true
} else {
// field is NOT empty
return false
}
@KanshuYokoo
KanshuYokoo / DispatchQueue.main.async.swift
Created September 19, 2018 14:34
ios, swift. call function from main thread
DispatchQueue.main.async(execute: {
// call any function ex. doSomething()
self.doSomething()
})
@KanshuYokoo
KanshuYokoo / ios go back to home
Created September 17, 2018 13:26
iso swift go to home
UIControl().sendAction(#selector(NSXPCConnection.suspend),
to: UIApplication.shared, for: nil)