Skip to content

Instantly share code, notes, and snippets.

View WonderJeffy's full-sized avatar
💭
good good working,day day make money

Jeffy WonderJeffy

💭
good good working,day day make money
View GitHub Profile
@WonderJeffy
WonderJeffy / TightLabel.Swift
Created June 6, 2025 10:21
自定义 UILabel, 使用 byTruncatingTail 但是没有右侧间距
class TightLabel: UILabel {
override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets(top: 0, left: -2, bottom: 0, right: -2)
super.drawText(in: rect.inset(by: insets))
}
override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width, height: size.height)
}
@WonderJeffy
WonderJeffy / 圆角三角形.swift
Created March 28, 2025 06:26
SwiftUI 绘制圆角三角
struct RoundedEquilateralTriangle: Shape {
var sideLength: CGFloat
var leftRadius: CGFloat
var topRadius: CGFloat
var rightRadius: CGFloat
func path(in rect: CGRect) -> Path {
var path = Path()
let height = sideLength * sqrt(3) / 2 // 等边三角形的高
var currentSection = 0
extension MoviesSubViewController: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard collectionView == scrollView as? UICollectionView else { return }
let touches = scrollView.panGestureRecognizer.numberOfTouches
guard scrollView.isDecelerating && touches == 0 else { return }
guard collectionView.numberOfSections > currentSection else { return }
let cellCount = collectionView.numberOfItems(inSection: currentSection)
/// 二叉树节点
public class TreeNode {
public var val: Int
public var left: TreeNode?
public var right: TreeNode?
public init() { self.val = 0; self.left = nil; self.right = nil; }
public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }
public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
self.val = val
self.left = left
@WonderJeffy
WonderJeffy / .ignore
Created July 13, 2023 05:03
swift.git.ignore
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
extension UIColor {
static var randomPastelColor: UIColor {
return UIColor(
hue: .random(in: 0 ... 1),
saturation: 0.4,
brightness: 0.9,
alpha: 1.0
)
}
@WonderJeffy
WonderJeffy / xcode_open_terminal
Created April 6, 2021 11:25
Xcode 中快速打开当前项目终端
#!/bin/sh
if [ -n "$XcodeProjectPath" ]; then
open -a Terminal "$XcodeProjectPath"/..
else
open -a Terminal "$XcodeWorkspacePath"/..
fi