Skip to content

Instantly share code, notes, and snippets.

View DisappearPing's full-sized avatar

Disappear Ping DisappearPing

  • Taoyuan,Taiwan R.O.C
View GitHub Profile
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
let nsString = textView.text as NSString?
let newString = nsString?.replacingCharacters(in: range,
with: "\n• ")
textView.text = newString
textView.sizeToFit()
tableView.beginUpdates()
tableView.endUpdates()
@DisappearPing
DisappearPing / textField+delegate.swift
Last active May 5, 2022 03:27
dynamic block enter text in textfield delegate
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard textField == self.exportAmountTextField else { return true }
let oldString: NSString = (textField.text ?? "") as NSString
let resultString = oldString.replacingCharacters(in: range, with: string)
let doubleString = Double(resultString) ?? 0
if (string.trimmingCharacters(in: CharacterSet.decimalDigits).count == 0 || string == "" || string == ".") == false {
@DisappearPing
DisappearPing / iphone-popover.md
Created April 11, 2022 07:58 — forked from susanstevens/iphone-popover.md
How to Create a Popover on iPhone

How to Create a Popover on iPhone

Storyboard set up

Add your view controllers in storyboard. In the Size Inspector, change the simulated size of the popover view controller to "Freeform". This doesn't change the popover's size when you run the app, but it does make it easier to lay out subviews correctly.

storyboard

When adding the segue between view controllers, select "Present as Popover".

@DisappearPing
DisappearPing / textFieldDelegate
Created March 24, 2022 08:05
TextField limit enter string length
// TextField
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let textFieldText = textField.text,
let rangeOfTextToReplace = Range(range, in: textFieldText) else {
return false
}
let substringToReplace = textFieldText[rangeOfTextToReplace]
let count = textFieldText.count - substringToReplace.count + string.count
return count <= 10
@DisappearPing
DisappearPing / MyLocale.swift
Created April 21, 2020 03:50
In-app change language to lokalize temp gist
//
// Bundle-AppLocale.swift
// Radiant Tap Essentials
//
// Copyright © 2016 Aleksandar Vacić, Radiant Tap
// MIT License · http://choosealicense.com/licenses/mit/
//
import Foundation
import Lokalise
@DisappearPing
DisappearPing / RandomInt.swift
Created June 19, 2017 08:43
Swift 3 random int
let maxInt = 9
let randomFrom0ToMaxInt = arc4random_uniform(maxInt)
@DisappearPing
DisappearPing / TransparentNavProtocol.swift
Created May 31, 2017 02:41
Conform this protocol can help to set navigationBar is tanslucent or not
protocol TransparentNavProtocol {
func setTransparentNav()
func resetTransparentNav()
}
extension TransparentNavProtocol where Self: UIViewController {
func setTransparentNav() {
self.navigationController?.navigationBar.subviews[0].alpha = 0
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.isTranslucent = true
@DisappearPing
DisappearPing / RedBackNavProtocol.swift
Created May 31, 2017 02:39
Conform this protocol, you can just use setRedNavBar() to set red background and white tintColor navigationBar.
import UIKit
protocol RedBackNavProtocol {
func setRedNavBar()
}
extension RedBackNavProtocol where Self : UIViewController {
func setRedNavBar() {
self.navigationController?.navigationBar.barTintColor = UIColor.navigation_bar_red
self.navigationController?.navigationBar.tintColor = UIColor.white
@DisappearPing
DisappearPing / RedBackNavProtocol.swift
Created May 31, 2017 02:39
Conform this protocol, you can just use setRedNavBar() to set red background and white tintColor navigationBar.
import UIKit
protocol RedBackNavProtocol {
func setRedNavBar()
}
extension RedBackNavProtocol where Self : UIViewController {
func setRedNavBar() {
self.navigationController?.navigationBar.barTintColor = UIColor.navigation_bar_red
self.navigationController?.navigationBar.tintColor = UIColor.white
@DisappearPing
DisappearPing / DisableBlinkingCursor.swift
Created September 22, 2016 09:45
Hide(Disable) Flashing input Leverage(Blinking Cursor) swift 2.2
yourTextField.valueForKey("textInputTraits")?.setValue(UIColor.clearColor(), forKey: "insertionPointColor")