Skip to content

Instantly share code, notes, and snippets.

View getjennyli's full-sized avatar

Ka getjennyli

View GitHub Profile
@getjennyli
getjennyli / SwiftUI Widget Width
Created December 5, 2020 18:50
SwiftUI Widget Size
func smallWidgetWidth() -> CGFloat {
switch UIScreen.main.bounds.size {
case CGSize(width: 428, height: 926): // 12 Pro Max
return 170
case CGSize(width: 414, height: 896):
return 169
case CGSize(width: 390, height: 844): // 12
return 158
case CGSize(width: 375, height: 812): // 12 Mini
return 155
override func viewDidLoad() {
switch.setOn(userDefaultsValue, animated: false)
}
@objc func toggleSwitch() {
UserDefaults.standard.set(userDefaultsValue.isOn, forKey: "showMMSS")
UserDefaults.standard.synchronize()
}
func setupShadow() {
noCoverStyle.clipsToBounds = false
noCoverStyle.layer.shadowColor = UIColor(named: "secondaryLabel")?.cgColor
noCoverStyle.layer.shadowOpacity = 0.25
noCoverStyle.layer.shadowOffset = .zero
noCoverStyle.layer.shadowRadius = 6
noCoverStyle.layer.shadowPath = UIBezierPath(rect: noCoverStyle.bounds).cgPath
}
override func viewDidLoad() {
let interaction = UIContextMenuInteraction(delegate: self)
bookCoverContainer.addInteraction(interaction)
}
// MARK:- ContextMenu
@available(iOS 13.0, *)
extension bookDetailPlusVC: UIContextMenuInteractionDelegate {
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in
@getjennyli
getjennyli / Motion Effect
Created July 19, 2020 16:42
Add Motion Effect to item
let min = CGFloat(-15)
let max = CGFloat(15)
let xMotion = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .tiltAlongHorizontalAxis)
xMotion.minimumRelativeValue = min
xMotion.maximumRelativeValue = max
let yMotion = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.y", type: .tiltAlongVerticalAxis)
yMotion.minimumRelativeValue = min
yMotion.maximumRelativeValue = max
- 打开 Automator
- 新建快速操作
- 设置自动操作为没有输入,任何应用程序,勾选用输出内容替换所选文本
- 插入 Shell 脚本
date "+%Y-%m-%d %H:%M:%S" #定义你自己的时间戳格式,自行参考man date
<!--
JS 帮助函数
效果:词性彩色高亮。在指定的区块中,若有英语词性符号,则高亮成预定义的彩色背景
用法:将下列函数 querySelectorAll('#back')中的 back,换成含有英语词性的区块 ID
举例:比如正面字段所在区块 & lt;div id="front"> 包含了形如 Test - 'n. 测试 & apos; 这样的英语单词解释,需要高亮词性 n. 那么只要把下列函数中相应地方改为 querySelectorAll('#front')就可以了
-->
<script type="text/javascript">
var colorMap = {
'n.':'#3f3f41',
@getjennyli
getjennyli / Alerts
Created February 20, 2020 05:08
Alerts
@State private var showingScore = false
.alert(isPresented: $showingScore) {
Alert(title: Text(scoreTitle), message: Text("Your score is ???"), dismissButton: .default(Text("Continue")) {
self.askQuestion()
})
}
//to show alert
showingScore = true
.navigationBarTitle("BetterRest")
.navigationBarItems(trailing:
// button here
Button(action: calculateBedTime) {
Text("Calculate")
}
)
.random(in: 0...2)