Skip to content

Instantly share code, notes, and snippets.

@apatronl
apatronl / ButtonPanelView.swift
Last active June 14, 2020 05:45
Button Panel View Demo
import UIKit
fileprivate let buttonSize: CGFloat = 56
fileprivate let shadowOpacity: Float = 0.7
class ButtonPanelView: UIView {
lazy var menuButton: UIButton = {
let button = UIButton(frame: .zero)
button.setTitle("➕", for: .normal)
@objc private func handleTogglePanelButtonTapped(_ sender: UIButton) {
UIView.animate(
withDuration: 0.3, delay: 0, options: .curveEaseIn,
animations: {
self.expandedStackView.subviews.forEach { $0.isHidden = !$0.isHidden }
self.expandedStackView.isHidden = !self.expandedStackView.isHidden
})
}
import UIKit
fileprivate let buttonSize: CGFloat = 56
fileprivate let shadowOpacity: Float = 0.7
class ButtonPanelView: UIView {
lazy var menuButton: UIButton = {
let button = UIButton(frame: .zero)
button.setTitle("➕", for: .normal)
class ButtonPanelView: UIView {
// ...
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(red: 81/255, green: 166/255, blue: 219/255, alpha: 1)
layer.cornerRadius = buttonSize / 2
layer.shadowColor = UIColor.lightGray.cgColor
import UIKit
class HeartButton: UIButton {
private var isLiked = false
private let unlikedImage = UIImage(named: "heart_empty")
private let likedImage = UIImage(named: "heart_filled")
private let unlikedScale: CGFloat = 0.7
private let likedScale: CGFloat = 1.3
import UIKit
class HeartButton: UIButton {
private let unlikedImage = UIImage(named: "heart_empty")
private let likedImage = UIImage(named: "heart_filled")
override public init(frame: CGRect) {
super.init(frame: frame)
import UIKit
class HeartButton: UIButton {
private var isLiked = false
// ...
public func flipLikedState() {
isLiked = !isLiked
animate()
import SwiftUI
struct ContentView: View {
@State private var selectedColor = Color.black
var body: some View {
VStack(alignment: .center) {
Text("Color Picker Demo").foregroundColor(selectedColor).font(.largeTitle)
ColorPicker(
import UIKit
extension UITableViewCell {
class var identifier: String {
return String(describing: self)
}
}
import SwiftUI
import UIKit
struct NavigationBarColor: ViewModifier {
init(backgroundColor: UIColor, tintColor: UIColor) {
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithOpaqueBackground()
coloredAppearance.backgroundColor = backgroundColor
coloredAppearance.titleTextAttributes = [.foregroundColor: tintColor]