Skip to content

Instantly share code, notes, and snippets.

View Josscii's full-sized avatar
💭
??

Josscii Josscii

💭
??
View GitHub Profile
@Josscii
Josscii / drawing.md
Last active August 4, 2022 14:26
iOS 绘图那些事

iOS 绘图那些事

在 iOS 中,我们通过 Core Graphics (也叫 Quarz 2D) 来绘图,而在 Core Grapihcs 之上的 UIKit 又封装了如 UIBeizerPath 等高级 api,这里就来简单的谈谈基础和技巧。

draw(_:)

对于 UIView 来说,我们可以重写 draw(_:) 方法来进行绘图,官方文档中对它的描述是:

Specifically, UIKit creates and configures a graphics context for drawing and adjusts the transform of that context so that its origin matches the origin of your view’s bounds rectangle.
@Josscii
Josscii / iOS Navigation.md
Last active August 28, 2021 17:49
iOS Navigation Related Cheat Sheet

iOS Navigation Related Cheat Sheet

NavigationItem

每个 vc 都有自己的 navigationItem。

// 隐藏 push 的下一个 vc 的 back title。
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
@Josscii
Josscii / iOS-tips.md
Last active June 26, 2019 03:41
iOS tips

iOS Tips

记录一些 iOS 开发中的小 tip。

  1. origin 为负,子视图右下移动,origin 为正,子视图左上移动,contentOffset 同理。

  2. velocity 为正,为向左/上滑动,velocity 为负,为向右/下滑动。

  3. contentInset 会影响 contentOffset 的变化范围,top/left 影响 contentOffset 的初始值,但并不会改变 contentSize 的值。

@Josscii
Josscii / iOS 分页调研.md
Created September 15, 2017 07:29
iOS 分页调研

iOS 分页调研

最近在实现 iOS 中分页的时候,看了一下各大新闻 app 中的方案,初步总结如下:

今日头条

collectionView + 数据缓存的方案 + 没有 contentOffset 缓存

腾讯新闻

UIScrollView + 子视图 + 不控制视图数量,没有缓存机制

@Josscii
Josscii / wwdc notes.md
Last active September 8, 2018 14:20
WWDC 笔记

WWDC 笔记

Using Time Profiler in Instruments

直达链接

通过上图我们可以看到,每隔 1ms,instruments 会记录一次 call stack,然后把每个方法的调用次数累加,最后就得到需要分析的数据了。所以,time profiler 记录的并不是方法调用的 duration,而是方法在单位时间内调用的 times。

@Josscii
Josscii / time related.md
Created February 23, 2018 08:39
时间相关类的解释
@Josscii
Josscii / ios layout.md
Last active June 7, 2018 10:54
iOS 布局总结

iOS 布局总结

写了这么久的 iOS,基本都是和界面布局打交道,平常在编码的过程中也逐渐积累了一些关于布局的心得,这里做个总结,既是对前面工作的总结,也希望能够给读这篇文章的人一些收获。

ViewController 的 View

从 iOS 7 开始到 iOS 10,由于有了高斯模糊的 bar,ViewController 默认开启全屏布局,UIViewController 增加了两个属性:

open var edgesForExtendedLayout: UIRectEdge // Defaults to UIRectEdgeAll

open var extendedLayoutIncludesOpaqueBars: Bool // Defaults to NO, but bars are translucent by default on 7_0.

@Josscii
Josscii / SwiftArray.md
Created September 4, 2018 09:30
Swift Array Cheat Sheet

Swift Array Cheat Sheet

初始化数组:

let arr = Array<Int>()
let arr1 = [Int]()
let arr2: [Int] = []
let arr3 = [1,2,3]
let arr4 = Array<Int>(repeating: 1, count: 3)
@Josscii
Josscii / Button.swift
Last active May 3, 2020 07:39
支持上下左右图片文字布局的 button,支持 xib
import UIKit
@IBDesignable
class Button: UIButton {
enum TextPosition: Int {
case top
case left
case bottom
case right
}
@Josscii
Josscii / BackgroundButton.swift
Last active May 3, 2020 07:38
让 UIButton 支持设置不同状态下背景颜色,支持 xib
import UIKit
// https://spin.atomicobject.com/2018/04/25/uibutton-background-color/
// Declare a global var to produce a unique address as the assoc object handle
private var normalColorHandle: UInt8 = 0
private var disabledColorHandle: UInt8 = 0
private var highlightedColorHandle: UInt8 = 0
private var selectedColorHandle: UInt8 = 0