MoviaBox/ShortPlay/Base/Extension/String+SPAdd.swift
2025-04-16 18:22:12 +08:00

37 lines
930 B
Swift

//
// String+SPAdd.swift
// ShortPlay
//
// Created by on 2025/4/8.
//
import UIKit
import SmartCodable
extension String: SmartCodable {
func length() -> Int {
return self.ocString().length
}
func ocString() -> NSString {
return self as NSString
}
static func timeZone() -> String {
let timeZone = NSTimeZone.local as NSTimeZone
let timeZoneAbbreviation = timeZone.name.length() > 0 ? timeZone.name : "Unknown"
let timeZoneSecondsFromGMT = timeZone.secondsFromGMT / 3600
return String(format: "GMT+0%d:00", timeZoneSecondsFromGMT)
}
}
extension String {
///Size
func size(font: UIFont, size: CGSize = CGSize(width: CGFloat(MAXFLOAT), height: CGFloat(MAXFLOAT))) -> CGSize{
let string: NSString = self as NSString
return string.size(for: font, size: size, mode: .byWordWrapping)
}
}