UI
所属分类:硬件设计
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2023-09-25 07:59:20
上 传 者:
sh-1993
说明: 自动布局:以编程方式创建约束,
(Auto Layout: Programmatically Creating Constraints,)
文件列表:
UI.xcodeproj/ (0, 2024-01-04)
UI.xcodeproj/project.pbxproj (83701, 2024-01-04)
UI.xcodeproj/project.xcworkspace/ (0, 2024-01-04)
UI.xcodeproj/project.xcworkspace/contents.xcworkspacedata (135, 2024-01-04)
UI.xcodeproj/project.xcworkspace/xcshareddata/ (0, 2024-01-04)
UI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (238, 2024-01-04)
UI.xcodeproj/xcshareddata/ (0, 2024-01-04)
UI.xcodeproj/xcshareddata/xcschemes/ (0, 2024-01-04)
UI.xcodeproj/xcshareddata/xcschemes/UI.xcscheme (2795, 2024-01-04)
UI/ (0, 2024-01-04)
UI/Resources/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/AccentColor.colorset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/AccentColor.colorset/Contents.json (123, 2024-01-04)
UI/Resources/Assets.xcassets/AppIcon.appiconset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json (1591, 2024-01-04)
UI/Resources/Assets.xcassets/Contents.json (63, 2024-01-04)
UI/Resources/Assets.xcassets/Jmy.imageset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/Jmy.imageset/Contents.json (301, 2024-01-04)
UI/Resources/Assets.xcassets/Jmy.imageset/Jmy.png (685231, 2024-01-04)
UI/Resources/Assets.xcassets/Swift.imageset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/Swift.imageset/Contents.json (303, 2024-01-04)
UI/Resources/Assets.xcassets/Swift.imageset/Swift.png (23515, 2024-01-04)
UI/Resources/Assets.xcassets/imgHighlighted.imageset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/imgHighlighted.imageset/Contents.json (400, 2024-01-04)
UI/Resources/Assets.xcassets/imgHighlighted.imageset/imgHighlighted.png (441, 2024-01-04)
UI/Resources/Assets.xcassets/imgHighlighted.imageset/imgHighlighted@2x.png (777, 2024-01-04)
UI/Resources/Assets.xcassets/imgHighlighted.imageset/imgHighlighted@3x.png (977, 2024-01-04)
UI/Resources/Assets.xcassets/imgNormal.imageset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/imgNormal.imageset/Contents.json (385, 2024-01-04)
UI/Resources/Assets.xcassets/imgNormal.imageset/imgNormal.png (260, 2024-01-04)
UI/Resources/Assets.xcassets/imgNormal.imageset/imgNormal@2x.png (372, 2024-01-04)
UI/Resources/Assets.xcassets/imgNormal.imageset/imgNormal@3x.png (516, 2024-01-04)
UI/Resources/Assets.xcassets/imgSingleTouched.imageset/ (0, 2024-01-04)
UI/Resources/Assets.xcassets/imgSingleTouched.imageset/Contents.json (406, 2024-01-04)
UI/Resources/Assets.xcassets/imgSingleTouched.imageset/imgSingleTouched.png (227, 2024-01-04)
UI/Resources/Assets.xcassets/imgSingleTouched.imageset/imgSingleTouched@2x.png (321, 2024-01-04)
UI/Resources/Assets.xcassets/imgSingleTouched.imageset/imgSingleTouched@3x.png (402, 2024-01-04)
... ...
# UI
UI is a DSL(Domain Specific Language) to make **Auto Layout and others** easy on iOS.
## [Extensions](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Extensions)
### [Swift Standard Library](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Extensions/SwiftStandardLibrary)
- [String](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/SwiftStandardLibrary/String.swift)
- [Dictionary](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/SwiftStandardLibrary/Dictionary.swift)
- [Optional](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/SwiftStandardLibrary/Optional.swift)
- [CaseIterable](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/SwiftStandardLibrary/CaseIterable.swift)
- [Collection](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/SwiftStandardLibrary/Collection.swift)
- [LiteralType](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/SwiftStandardLibrary/LiteralType.swift)
### [Foundation](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Extensions/Foundation)
- [Date](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/Foundation/Date.swift)
- [FileManager](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/Foundation/FileManager.swift)
- [NSAttributedString](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/Foundation/NSAttributedString.swift)
- [NSMutableAttributedString](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/Foundation/NSMutableAttributedString.swift)
### [CoreAnimation](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Extensions/CoreAnimation)
- [CALayer](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/CoreAnimation/CALayer.swift)
### [UIKit](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Extensions/UIKit)
- [UIApplication](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/Foundation/UIApplication.swift)
- [UIStoryboard](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIStoryboard.swift)
- [UINavigationController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIViewController.swift)
- [UIViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIViewController.swift)
- [UIAlertController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIAlertController.swift)
- [UIAlertAction](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIAlertAction.swift)
- [UIActivity](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIActivity.swift)
- [UIButton](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIButton.swift)
- [UILabel](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UILabel.swift)
- [UIColor](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIColor.swift)
- [UITableView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UITableView.swift)
- [UICollectionView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UICollectionView.swift)
- [FlowLayoutMetric](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Defines/FlowLayoutMetric.swift)
- [UITextView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UITextView.swift)
- [UIScrollView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIScrollView.swift)
- [UIView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIView.swift) (NSLayoutAnchor, NSLayoutConstraint, Visual Format Language)
- [UIImageView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIImageView.swift) (Asynchronously, Synchronously, Download, Retrieve Memory / Disk Cache)
## [Views](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Views)
[Commons](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Views/Commons)
- [NavigationView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/NavigationView.swift)
- [TabView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/TabView.swift)
- [SelfSizedCollectionView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/SelfSizedCollectionView.swift)
- [FloatingButton](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/FloatingButton.swift)
- [PinterestLayout](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/PinterestLayout.swift)
- [SafariActivity](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/SafariActivity.swift)
- [ActionSheet](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/ActionSheet.swift)
- [TapSlider](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/TapSlider.swift)
- [ChevronDownButton](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/ChevronDownButton.swift)
- [UIPlaceholderTextView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/UIPlaceholderTextView.swift)
## [ViewControllers](https://github.com/YangJinmo/UI/tree/main/UI/Sources/ViewControllers)
[Bases](https://github.com/YangJinmo/UI/tree/main/UI/Sources/ViewControllers/Bases)
- [BaseViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/ViewControllers/Bases/BaseViewController.swift)
- [BaseTabViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/ViewControllers/Bases/BaseTabViewController.swift)
[Commons](https://github.com/YangJinmo/UI/tree/main/UI/Sources/ViewControllers/Commons)
- [TabBarController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/ViewControllers/Commons/TabBarController.swift)
- [WebViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/ViewControllers/Commons/WebViewController.swift)
- [ImagePresentViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/ViewControllers/Commons/ImagePresentViewController.swift)
- [MailComposeViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/ViewControllers/Commons/MailComposeViewController.swift)
## [Commons](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Commons)
- [BuildConfiguration](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Commons/BuildConfiguration.swift)
- [Log](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Commons/Log.swift)
## [Defines](https://github.com/YangJinmo/UI/tree/main/UI/Sources/Commons)
- [Identifiable](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Defines/Identifiable.swift)
## Usage
### [UIStoryboard](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIStoryboard.swift)
```swift
let vc = MainViewController.instantiate()
```
```swift
class MainViewController: UIViewController {
static func instantiate() -> Self {
return Self.from(storyboardName: .home, bundle: Bundle.main)
}
}
```
### [UIViewController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIViewController.swift)
**[UINavigationController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIViewController.swift)**
```swift
present(SearchViewController())
```
```swift
present(DelegateViewController(delegate: self))
```
```swift
present(
UIAlertController
.actionSheet(title: "title", message: "message")
.action(title: "default", style: .default) { _ in
"default".log()
}
.action(title: "destructive", style: .destructive) { _ in
"destructive".log()
}
.action(title: "", style: .cancel) { _ in
"cancel".log()
}
) {
"completion".log()
}
```
**[UIAlertController](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIAlertController.swift)**
alert
```swift
alert(
title: " ",
message: " \n ."
) { _ in
self.popViewController()
}
```
```swift
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
alert(message: message) { _ in
completionHandler()
}
}
```
alertOption
```swift
alertOption(
title: "title",
message: "message"
) { _ in
"confirmHandler".log()
} cancelHandler: { _ in
"cancelHandler".log()
} completion: {
"completion".log()
}
```
```swift
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) {
alertOption(
message: message,
confirmHandler: { _ in
completionHandler(true)
},
cancelHandler: { _ in
completionHandler(false)
}
)
}
```
actionSheet
```swift
actionSheet(
title: "title",
message: "message",
actions:
.default("default", { _ in
"default".log()
}),
.destructive("destructive", { _ in
"destructive".log()
})
) { _ in
"cancel".log()
} completion: {
"completion".log()
}
```
### [Toast](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIViewController.swift)
```swift
toast(" \n\n \n .")
```
```swift
toast("UI .", bottom: true)
```
```swift
toast(error.localizedDescription)
```
### [UITableView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UITableView.swift) (register, dequeueReusableCell)
```swift
class ViewController: UIViewController {
let items: [Item] = ["1", "2", "3"]
lazy var tableView: UITableView = {
let tableView = UITableView()
tableView.dataSource = self
tableView.delegate = self
tableView.register(TableViewCell.self)
return tableView
}()
}
extension TableViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: TableViewCell = tableView.dequeueReusableCell(for: indexPath)
cell.textLabel?.text = items[indexPath.row]
return cell
}
}
```
### [UICollectionView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UICollectionView.swift) (register, dequeueReusableCell)
```swift
class ViewController: UIViewController {
var searches: [Search] = [
Search(
isExpand: false,
title: " ",
terms: ["", "", "", "", ""]
),
Search(
isExpand: false,
title: " ",
terms: ["", "", "", "", ""]
),
Search(
isExpand: false,
title: " ",
terms: ["", "", "", "", ""]
),
]
lazy var collectionView: BaseCollectionView = {
let collectionView = BaseCollectionView(layout: flowLayout())
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(SearchTitleCell.self)
collectionView.register(SearchTermCell.self)
return collectionView
}()
}
extension CollectionViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return searches.count
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if searches[section].isExpand == true {
return searches[section].terms.count + 1
} else {
return 1
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.item {
case 0:
let cell: SearchTitleCell = collectionView.dequeueReusableCell(for: indexPath)
cell.bind(data: searches[indexPath.section])
return cell
default:
let cell: SearchTermCell = collectionView.dequeueReusableCell(for: indexPath)
cell.bind(
rank: indexPath.item,
term: searches[indexPath.section].terms[indexPath.item - 1]
)
return cell
}
}
}
```
### [FlowLayoutMetric](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Defines/FlowLayoutMetric.swift)
[flowLayout](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Defines/FlowLayoutMetric.swift)
```swift
lazy var collectionView: BaseCollectionView = {
let collectionView = BaseCollectionView(layout: flowLayout())
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(SearchTitleCell.self)
collectionView.register(SearchTermCell.self)
return collectionView
}()
```
[itemSize](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Defines/FlowLayoutMetric.swift)
```swift
extension CollectionViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
switch indexPath.item {
case 0:
return itemSize(width: collectionView, height: SearchTitleCell.itemHeight)
default:
return itemSize(width: collectionView, height: SearchTermCell.itemHeight)
}
}
}
```
[FlowLayoutMetric](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Defines/FlowLayoutMetric.swift) (protocol),
[UIEdgeInsets](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIEdgeInsets.swift) (uniform)
```swift
extension CollectionViewController: FlowLayoutMetric {
var numberOfItemForRow: CGFloat {
1
}
var sectionInset: UIEdgeInsets {
.uniform(size: 0)
}
var minimumLineSpacing: CGFloat {
1
}
var minimumInteritemSpacing: CGFloat {
0
}
}
```
### [UIView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIView.swift)
```swift
class ViewController: UIViewController {
lazy var pushButton = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
view.add(
pushButton,
heightConstant: 44,
center: view
)
}
}
```
```swift
class ViewController: UIViewController {
lazy var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
view.add(
tableView,
top: view.safeAreaLayoutGuide.topAnchor,
left: view.safeAreaLayoutGuide.leftAnchor,
right: view.safeAreaLayoutGuide.rightAnchor,
bottom: view.bottomAnchor
)
}
}
```
```swift
class ViewController: UIViewController {
lazy var collectionView = UICollectionView()
override func viewDidLoad() {
super.viewDidLoad()
view.add(
collectionView,
edges: view
)
}
}
```
### [UILabel](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UILabel.swift)
lineSpacing
```swift
lazy var explainLabel: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 22, weight: .light)
label.textColor = .secondaryLabel
label.text = "!\nzzimss."
label.lineSpacing()
return label
}()
```
### [UIColor](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/UIColor.swift)
rgb, white, random
```swift
let highlight = UIColor.rgb(r: 179, g: 236, b: 230)
```
```swift
let gray250 = UIColor.white(250)
```
```swift
let purple = UIColor.hex(0xAB47BC)
```
```swift
let randomColor = UIColor.random()
```
### [Optional](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/Optional.swift)
isNilOrEmpty
```swift
func toast(_ text: String?) {
guard !text.isNilOrEmpty else { return }
print(text)
}
```
### [NSMutableAttributedString](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Extensions/UIKit/NSMutableAttributedString.swift)
```swift
lazy var explainLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.attributedText = NSMutableAttributedString()
.light("!\n", size: 22)
.medium("!", size: 22)
return label
}
```
### [FloatingButton](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/FloatingButton.swift)
```swift
final class ViewController: UIViewController {
lazy var floatingButton = FloatingButton(view: view, scrollView: tableView)
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
floatingButton.create()
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
floatingButton.remove()
}
}
```
```swift
extension ViewController: UIScrollViewDelegate {
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
startScrolling()
}
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
startScrolling()
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate {
stoppedScrolling(scrollView: scrollView)
}
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
stoppedScrolling(scrollView: scrollView)
}
private func startScrolling() {
view.endEditing(true)
floatingButton?.hide()
}
private func stoppedScrolling(scrollView: UIScrollView) {
scrollView.contentOffset.y == 0
? floatingButton.hide()
: floatingButton.show()
}
}
```
### [PinterestLayout](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/PinterestLayout.swift)
```swift
final class ViewController: UIViewController {
lazy var collectionLayout = PinterestLayout(delegate: self)
lazy var collectionView = BaseCollectionView(layout: collectionLayout)
}
```
### [TabView](https://github.com/YangJinmo/UI/blob/main/UI/Sources/Views/Commons/TabView.swift)
```swift
class ScrollableStackViewController: UIViewController {
lazy var tabView = TabView(titleText: vcName)
lazy var titleLabel = UILabel.makeForText(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
)
lazy var subtitleLabel = UILabel.makeForText(
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam ... ...
近期下载者:
相关文件:
收藏者: