Skip to content

Instantly share code, notes, and snippets.

View calvingit's full-sized avatar
🎯
Focusing

Wen calvingit

🎯
Focusing
View GitHub Profile
// AppStorage 需要 iOS 14 才可以用
@propertyWrapper
public struct UserDefault<Value>: DynamicProperty {
@State private var value: Value
let key: String
let store: UserDefaults
public init(
@IBDesignable
class GradientView: UIView {
// implement cgcolorgradient in the next section
@IBInspectable var startColor: UIColor? {
didSet { gradientLayer.colors = cgColorGradient }
}
@IBInspectable var endColor: UIColor? {
didSet { gradientLayer.colors = cgColorGradient }
extension String {
// 移除空白
func removingWhitespace() -> String {
let whitespacePattern = "\\s+"
let regex = try? NSRegularExpression(pattern: whitespacePattern, options: .caseInsensitive)
let range = NSRange(location: 0, length: count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "") ?? self
}
import SwiftUI
import UIKit
/// 创建一个SwiftUI的容器View,将UIViewControler包含在内,即可预览
///
/// 如果要预览这个ViewController
///
/// ```swift
/// class ViewController: UIViewController {
import UIKit
// MARK: - Initializers
extension UIAlertController {
/// Create new alert view controller.
///
/// - Parameters:
/// - style: alert controller's style.
/// - title: alert controller's title.
extension View {
func hideNavigationBar(_ hidden: Bool = true) -> some View {
if #available(iOS 16.0, *) {
return self.toolbar(hidden ? .hidden : .visible)
} else {
// Fallback on earlier versions
return self.navigationBarHidden(hidden)
}
}
}

Popover

class ViewController: UIViewController {

    @IBAction func clicked(_ sender: Any) {

        let vc = UIHostingController(rootView: AlertView(cancel: {
            //
            self.dismiss(animated: true)
extension UIGestureRecognizer {
private struct AssociatedKeys {
static var action = "action"
}
private typealias GestureAction = ((UIGestureRecognizer) -> Void)
private var action: GestureAction? {
get {

1. UITableView 在编辑模式下可以实现默认的排序功能

    // Override to support rearranging the table view.
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
        tableView.moveRow(at: fromIndexPath, to: to)
    }
       
    // Override to support conditional rearranging of the table view.
    override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {

https 代理

~/.gitconfig 文件里配置

[http]
  proxy = socks5://127.0.0.1:1080
[https "github.com"]
  proxy = socks5://127.0.0.1:1080
 sslverify = false