Skip to content

Instantly share code, notes, and snippets.

View KanshuYokoo's full-sized avatar

kkaannnssshh KanshuYokoo

View GitHub Profile
@KanshuYokoo
KanshuYokoo / ios viewController initialize
Created September 15, 2018 07:46
initialize view controler ios swift
convenience init() {
self.init(nibName:nil, bundle:nil)
}
// This extends the superclass.
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
// This is also necessary when extending the superclass.
@KanshuYokoo
KanshuYokoo / ios date picker action
Created September 16, 2018 18:02
ios swift 4 date picker
@IBAction func datePickerAction(_ sender: UITextField) {
let datePickerView:UIDatePicker = UIDatePicker()
datePickerView.datePickerMode = UIDatePickerMode.date
sender.inputView = datePickerView
datePickerView.addTarget(self, action: #selector(ViewController.datePickerValueChanged), for: UIControlEvents.valueChanged)
}
@objc func datePickerValueChanged(sender:UIDatePicker) {
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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
}
}