Skip to content

Instantly share code, notes, and snippets.

View Pakkapon's full-sized avatar

Pakkapon Kitpsaisansup Pakkapon

  • Bangkok
View GitHub Profile
// this method for trim text that have a lot of whitespace and newline to show just only max 2 lines and remove leading and traling of whitespace and new lines
func trimJustTwoUnderlines() -> String {
let characters = Array(self)
var newText: [String.Element] = []
var tempLineCounts: Int = 0
if characters.count > 1 {
for index in 0...characters.count-1 {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if textView.text.count > 1 {
let last2characters = String(textView.text.suffix(2))
let array = last2characters.components(separatedBy: CharacterSet.newlines)
print("line count :\(array.count)")
if array.count > 2 && text == "\n" {
@Pakkapon
Pakkapon / gist:6688d625b0597fc9a92a483b6f085b12
Created March 6, 2018 04:38
SetColorNavigationBar.swift
public func SetColorUINavigation (NavColor navColor : UIColor , StatusBarStyle style : UIStatusBarStyle, StatusBarColor statusBarColor : UIColor) {
UINavigationBar.appearance().backgroundColor = navColor
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) {
statusBar.backgroundColor = statusBarColor
UIApplication.shared.statusBarStyle = style
}
}
import Foundation
import UIKit
extension UITextView{
func setPlaceholder(PlaceholderText text : String) {
let placeholderLabel = UILabel()
import MobileCoreServices
import UIKit
class CameraHandler: NSObject {
private let imagePicker = UIImagePickerController()
private let isPhotoLibraryAvailable = UIImagePickerController.isSourceTypeAvailable(.photoLibrary)
private let isSavedPhotoAlbumAvailable = UIImagePickerController.isSourceTypeAvailable(.savedPhotosAlbum)
private let isCameraAvailable = UIImagePickerController.isSourceTypeAvailable(.camera)
private let isRearCameraAvailable = UIImagePickerController.isCameraDeviceAvailable(.rear)