最近又开始写不少业务代码了,有些小知识点小坑,用这个系列记录一下。
iOS 开发小记-01
iOS 开发小记-02
1. UIView 添加虚线边框 Dash Line
let dashBorderLayer = CAShapeLayer()
let path = UIBezierPath(roundedRect: holderView.bounds, cornerRadius: 4)
dashBorderLayer.path = path.cgPath
dashBorderLayer.strokeColor = Color.lightGreyText.withAlphaComponent(0.4).cgColor
dashBorderLayer.lineDashPattern = [3, 3]
dashBorderLayer.backgroundColor = UIColor.clear.cgColor
dashBorderLayer.fillColor = UIColor.clear.cgColor
holderView.layer.addSublayer(dashBorderLayer)
2. UITextField 输入框缩进(使用 leftView)
let textFieldLeftView = UIView(frame: CGRect(x: 0, y: 0, width: 12, height: 10))
textFieldLeftView.backgroundColor = UIColor.clear
missionNameTextField.leftView = textFieldLeftView
missionNameTextField.leftViewMode = .always
missionNameTextField.contentVerticalAlignment = .center
3. UIButton 代码触发点击事件
button.sendActions(for: .touchUpInside)
4. 导出 Xcode 代码字体配色
Xcode 的配置字体样式位于:
~/Library/Developer/Xcode/UserData/FontAndColorThemes
复制出来即可