原创 Swift Double向上取整和向下取整、Double轉Int/String

floor()函數:向下取整,取小於等於這個數的最大整數 (floor(3.94) = 3) ceil()函數:向上取整,取大於等於這個數的最小整數 (ceil(3.14) = 4) import Foundation exte

原创 Swift關鍵字defer

defer 裏的代碼會在函數 return 之前執行,無論函數是從哪個分支 return的,包括有try catch的情況。 例如 defer { print("defer") } if sign { print

原创 Swift實現應用的多語言

選擇工程,添加一個語言 創建名爲Localization的strings文件,並在右側勾選語言 在strings文件裏分別定義字符串的值 "Cancel" = "Cancel"; "OK" = "OK"; "Cancel"

原创 iOS AVSpeechSynthesizer語音播報

使用系統自帶的語音播報指定的字符串,只需要調用下面一行代碼: [SpeechSynthesizerManager.shared speakOrder:@"Hello World"]; AVSpeechSynthesizer文件

原创 Swift String通過下標獲取子串、計算字符串的寬高、16進制轉10進制、String轉換爲AttributedString、使用正則驗證合法性

String通過下標獲取子串 extension String { func index(_ offset: Int) -> Index { return self.index(startIndex, of

原创 iOS UIViewController+Alert

#import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface UIViewController (Alert) - (void)showAlertController:

原创 Swift旋轉動畫

protocol RotationAnimatedProtocol { func startRotationAnimation() func stopRotationAnimation() } extension

原创 iOS UIView設置陰影 切單個圓角

設置陰影 - (void)addShadow:(UIColor *)color offset:(CGSize)offset { self.layer.shadowColor = color.CGColor; sel

原创 Swift獲取當前時間

獲取當前時間 時間戳/字符串 時間戳和字符串相互轉化 import Foundation extension Date { static func currentTimeInterval() -> Int64

原创 Swift自定義UIColor

import Foundation import UIKit extension UIColor { convenience init(hex: String) { self.init(hex:

原创 Swift 定義常量

import Foundation import UIKit let ScreenBounds = UIScreen.main.bounds let ScreenWidth = UIScreen.main.bounds.si

原创 JQuery判斷設備類型、判斷是否是微信瀏覽器

//判斷設備是否是手機還是電腦 function isMobileClient() { var userAgentInfo = navigator.userAgent; var Agents = n