This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State private var labelStyle: PickerLabelStyle = .label | |
@State private var selection: PickerItem = PickerItem.item1 | |
@State private var imageName: String = "circle.fill" | |
@State private var secondaryColor: Color = .primary | |
var body: some View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIColor { | |
convenience init?(hexString: String) { | |
let hexString = hexString.trimmingCharacters(in: .whitespacesAndNewlines) | |
let scanner = Scanner(string: hexString) | |
scanner.charactersToBeSkipped = CharacterSet(charactersIn: "#") | |
var color: UInt64 = 0 | |
if scanner.scanHexInt64(&color) { | |
self.init(hex: color, useOpacity: hexString.count > 7) | |
} else { | |
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func toHexString4(_ color:UIColor) -> String? { | |
var cgColor:CGColor = color.cgColor | |
if let name = cgColor.colorSpace?.name, name != CGColorSpace.sRGB { | |
cgColor = color.cgColor.converted(to: CGColorSpace(name: CGColorSpace.sRGB)!, intent: .defaultIntent, options: nil)! | |
} | |
let ciColor = CIColor(cgColor: cgColor) | |
return toHexString([ciColor.red, ciColor.green, ciColor.blue, ciColor.alpha]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func toHexString1(_ color:UIColor) -> String? { | |
guard let components = color.cgColor.components else { return nil } | |
return toHexString(components) | |
} | |
func toHexString2(_ color:UIColor) -> String? { | |
var r: CGFloat = 0 | |
var g: CGFloat = 0 | |
var b: CGFloat = 0 | |
var a: CGFloat = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
if let split = splitViewController, split.isCollapsed { | |
if let indexPath = tableView.indexPathForSelectedRow { | |
tableView.deselectRow(at: indexPath, animated: true) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewWillAppear(_ animated: Bool) { | |
if let split = splitViewController { | |
self.clearsSelectionOnViewWillAppear = split.isCollapsed | |
} | |
super.viewWillAppear(animated) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SURMasterTableViewCell: UITableViewCell { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
updateAccessoryType() | |
} | |
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | |
super.traitCollectionDidChange(previousTraitCollection) | |
updateAccessoryType() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { | |
return true | |
} | |
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { | |
if sourceIndexPath.section != destinationIndexPath.section { return } | |
SURDataManager.shared.move(from: sourceIndexPath, to: destinationIndexPath) | |
} | |
func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] { | |
let itemProvider = NSItemProvider(object: "sample name" as NSString) | |
return [UIDragItem(itemProvider: itemProvider)] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) { | |
if coordinator.items.count == 0 { return } | |
let destinationIndexPath = coordinator.destinationIndexPath ?? IndexPath(row: editImages.images.count, section: 0) | |
let cellImageWidth = tableView.frame.size.width - tableView.layoutMargins.left - tableView.layoutMargins.right | |
for item in coordinator.items { | |
let itemProvider = item.dragItem.itemProvider | |
if !itemProvider.canLoadObject(ofClass: UIImage.self) { continue } | |
itemProvider.loadObject(ofClass: UIImage.self) {(object, error) in | |
guard let image = object as? UIImage else { return } |
NewerOlder