Skip to content

Instantly share code, notes, and snippets.

View Lancewer's full-sized avatar
🎯
Focusing

Lancewer Lancewer

🎯
Focusing
View GitHub Profile
@Lancewer
Lancewer / UUID.java
Last active November 30, 2017 13:30 — forked from fumokmm/UUIDTest.java
[create UUID in Java] #Java
java.util.UUID.randomUUID().toString()
@Lancewer
Lancewer / react_template.jsx
Created November 30, 2017 21:07
[React Template] new React Template from official site #React #Javascript #JS #template #init #HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>
<body>
@Lancewer
Lancewer / SimpleAlertController.swift
Created December 11, 2017 03:39
[Simple AlertController in iOS] how to create a basic alert controller with a textfield in iOS #iOS #Swift #alert #alertController #textField
@IBAction func addName(_ sender: Any) {
let alert = UIAlertController(title: "New Name", message: "Add a new name", preferredStyle: .alert)
let saveAction = UIAlertAction(title: "Save", style: .default) {
[unowned self] action in
guard let textField = alert.textFields?.first,
let nameToSave = textField.text else {
return
}
self.names.append(nameToSave)
self.tableView.reloadData()
@Lancewer
Lancewer / CustomizeTabBarItem.swift
Last active December 20, 2017 23:38
[Customize UITabBarItem] customize UITabBarItem with image and text color #UITabBarItem #customize #Appearence #Image
func setupTabBarItem(){
var defaultIconImage = UIImage(named: "035")
if let image = defaultIconImage {
defaultIconImage = image.withRenderingMode(.alwaysOriginal) //Keep image render model original is important!
}
var selectedIconImage = UIImage(named: "020")
if let image = selectedIconImage {
selectedIconImage = image.withRenderingMode(.alwaysOriginal)
}
@Lancewer
Lancewer / CollectionViewCell.swift
Last active May 17, 2023 09:05
[Collection Single Selection] single selection in UICollectionView with swift #swift #UICollectionView #selection #select #single select
//custom cell class
import UIKit
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel!
override var isSelected: Bool{
didSet(newValue){
contentView.backgroundColor = newValue ? UIColor.green : UIColor.white
@Lancewer
Lancewer / CloseKeyboard.swift
Created December 23, 2017 09:34
[Close keyboard] close all the keyboard on the screen in iOS #iOS #keyboard #first responder #close
//You can drag a tapGestureRecongizer to the very bottom view, and link a IBAction like below to it
@IBAction func closeAllKeyborad(_ sender: Any) {
view.endEditing(true)
}
@Lancewer
Lancewer / getAllManagedID.swift
Created January 11, 2018 08:57
[GetManagedObjectID] get managedObjectID created by CoreData #CoreData #iOS #ID #swift #ObjectID
let itemIDsFetchRequest = NSFetchRequest<NSManagedObjectID>(entityName: "ClothItem")
itemIDsFetchRequest.resultType = .managedObjectIDResultType
do {
let ids = try managedContext!.fetch(itemIDsFetchRequest)
print(ids.first!.uriRepresentation().absoluteString)
}catch let error as NSError {
print("Fetch item failed:\(error), \(error.userInfo)")
}
@Lancewer
Lancewer / FetchPropertiesOnDemand.swift
Created January 12, 2018 07:29
[FetchPropertiesOnDemand] Fetch part of properties in an managed object #CoreData #Fetch
let briefInfoFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "ClothItem")
briefInfoFetchRequest.resultType = .dictionaryResultType
briefInfoFetchRequest.returnsObjectsAsFaults = false
let desc = NSExpressionDescription()
desc.name = "mainPhoto"
desc.expression = NSExpression(forKeyPath: "mainPhotoURLString")
desc.isStoredInExternalRecord = true
desc.expressionResultType = .stringAttributeType
@Lancewer
Lancewer / panGestureBasicUsage.swift
Created January 15, 2018 14:19
[PanGestureBasicUsage] basic usage of pan gesture recongizer
// The Pan Gesture
func createPanGestureRecognizer(targetView: UIImageView) {
var panGesture = UIPanGestureRecognizer(target: self, action:#selector(handlePanGesture(_:)))
targetView.addGestureRecognizer(panGesture)
}
@objc func handlePanGesture(panGesture: UIPanGestureRecognizer) {
// get translation
let translation = panGesture.translation(in: view)
// This line is reset translation point to zero, let the next translation base on
@Lancewer
Lancewer / Readme.md
Created January 17, 2018 01:24
[AddSubviewToSuperViewCenter] how to add a subview to superview's center #UIView #center #iOS #OC

#This simple snippet shows how to add a subview to superview's center.