The UITableView relies on 2 different delegates to do it's job:
- UITableViewDataSource
- UITableViewDelegate
The data source tells the view what to display. The delegate tells the view how to respond to specific events like when a user taps on a cell.
import UIKit | |
import PlaygroundSupport | |
// MARK: - Setup | |
let view: UIView = { | |
let view = UIView(frame: .init(x: 0, y: 0, width: 300, height: 300)) | |
view.backgroundColor = .white | |
return view |
import UIKit | |
import PlaygroundSupport | |
// MARK: - Setup | |
let view: UIView = { | |
let view = UIView(frame: .init(x: 0, y: 0, width: 300, height: 300)) | |
view.backgroundColor = .white | |
return view |
import Foundation | |
class CounterTopDishwasher { | |
var dishes: [String] = [] | |
var space = 10 | |
var isClean = false | |
func run() { | |
if (!isClean) { | |
isClean = true |
struct RatingStar: View { | |
var rating: CGFloat | |
var color: Color | |
var index: Int | |
var maskRatio: CGFloat { | |
let mask = rating - CGFloat(index) | |
Star Index | Mask Value | After normailzation | |
---|---|---|---|
0 | 3.6 | 1 | |
1 | 2.6 | 1 | |
2 | 1.6 | 1 | |
3 | 0.6 | 0.6 | |
4 | 0 | 0 |
public struct FiveStarView: View { | |
var rating: Decimal | |
var color: Color | |
var backgroundColor: Color | |
public init( | |
rating: Decimal, | |
color: Color = .red, | |
backgroundColor: Color = .gray | |
) { |
private struct StarImage: View { | |
var body: some View { | |
Image(systemName: "star.fill") | |
.resizable() | |
.aspectRatio(contentMode: .fill) | |
} | |
} |
struct ContentView: View { | |
@State var shouldShow = false | |
var body: some View { | |
Text("Press me!") | |
.font(.largeTitle) | |
.fontWeight(.semibold) | |
.foregroundColor(.orange) | |
.onTapGesture { shouldShow = true } |
import SwiftUI | |
struct ShetlerView: View { | |
@ObservedObject var scheduler = Scheduler() | |
var body: some View { | |
List(0..<scheduler.reservableTimes.count) { index in | |
let time = scheduler.reservableTimes[index] | |
Text(time.time) | |
.foregroundColor(scheduler.selectedTimes.contains(time) ? .gray : .black) |