This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 // 等边三角形的高 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 二叉树节点 | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIColor { | |
static var randomPastelColor: UIColor { | |
return UIColor( | |
hue: .random(in: 0 ... 1), | |
saturation: 0.4, | |
brightness: 0.9, | |
alpha: 1.0 | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -n "$XcodeProjectPath" ]; then | |
open -a Terminal "$XcodeProjectPath"/.. | |
else | |
open -a Terminal "$XcodeWorkspacePath"/.. | |
fi |