Rename repo and app

This commit is contained in:
Christoph Hagen
2022-04-28 15:54:13 +02:00
parent 1636932805
commit c119885743
78 changed files with 91 additions and 34 deletions

View File

@@ -0,0 +1,42 @@
// Copyright 2018, Ralf Ebert
// License https://opensource.org/licenses/MIT
// License https://creativecommons.org/publicdomain/zero/1.0/
// Source https://www.ralfebert.de/ios-examples/uikit/choicepopover/
import UIKit
/**
By default, when you use:
```
controller.modalPresentationStyle = .popover
```
in a horizontally compact environment (iPhone in portrait mode), this option behaves the same as fullScreen.
You can make it to always show a popover by using:
```
let presentationController = AlwaysPresentAsPopover.configurePresentation(forController: controller)
```
*/
class AlwaysPresentAsPopover : NSObject, UIPopoverPresentationControllerDelegate {
// `sharedInstance` because the delegate property is weak - the delegate instance needs to be retained.
private static let sharedInstance = AlwaysPresentAsPopover()
private override init() {
super.init()
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
static func configurePresentation(forController controller : UIViewController) -> UIPopoverPresentationController {
controller.modalPresentationStyle = .popover
let presentationController = controller.presentationController as! UIPopoverPresentationController
presentationController.delegate = AlwaysPresentAsPopover.sharedInstance
return presentationController
}
}

View File

@@ -0,0 +1,53 @@
//
// CropView.swift
// CapFinder
//
// Created by User on 31.01.18.
// Copyright © 2018 User. All rights reserved.
//
import UIKit
//@IBDesignable
class CropView: UIView {
@IBInspectable var lineColor: UIColor = UIColor.black
@IBInspectable var lineWidth: Float = 2
@IBInspectable var relativeSize: Float = 0.6 {
didSet { size = CGFloat(relativeSize) / 2 }
}
private var size: CGFloat = 0.3
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func draw(_ rect: CGRect) {
let height = rect.height
let width = rect.width
let length = height > width ? width : height
let center = CGPoint(x: width / 2, y: height / 2)
let path = UIBezierPath()
path.lineWidth = CGFloat(self.lineWidth)
lineColor.setStroke()
path.addArc(
withCenter: center,
radius: length * size,
startAngle: 0,
endAngle: .pi * 2,
clockwise: true)
path.stroke()
}
}

View File

@@ -0,0 +1,99 @@
//
// RoundedButton.swift
// CapFinder
//
// Created by User on 01.02.18.
// Copyright © 2018 User. All rights reserved.
//
import Foundation
import UIKit
@IBDesignable
class RoundedButton: UIButton {
@IBInspectable var borderColor: UIColor = UIColor.black {
didSet {
layer.borderColor = borderColor.cgColor
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
//Normal state bg and border
@IBInspectable var normalBorderColor: UIColor? {
didSet {
layer.borderColor = normalBorderColor?.cgColor
}
}
@IBInspectable var normalBackgroundColor: UIColor? {
didSet {
setBgColorForState(color: normalBackgroundColor, forState: [])
}
}
//Highlighted state bg and border
@IBInspectable var highlightedBorderColor: UIColor?
@IBInspectable var highlightedBackgroundColor: UIColor? {
didSet {
setBgColorForState(color: highlightedBackgroundColor, forState: .highlighted)
}
}
private func setBgColorForState(color: UIColor?, forState: UIControl.State){
self.backgroundColor = color
// if color != nil {
// self.backgroundColor = color!
// setBackgroundImage(UIImage.imageWithColor(color: color!), for: forState)
// } else {
// setBackgroundImage(nil, for: forState)
// }
}
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = layer.frame.height / 2
// layer.cornerRadius = min(layer.frame.height, layer.frame.width) / 2
clipsToBounds = true
if borderWidth > 0 {
if state == [] && layer.borderColor == normalBorderColor?.cgColor {
layer.borderColor = normalBorderColor?.cgColor
} else if state == .highlighted && highlightedBorderColor != nil {
layer.borderColor = highlightedBorderColor!.cgColor
}
}
}
}
extension RoundedButton {
func set(template: String, with tint: UIColor) {
self.setImage(UIImage.templateImage(named: template), for: .normal)
self.tintColor = tint
self.borderColor = tint
}
}
//Extension Required by RoundedButton to create UIImage from UIColor
extension UIImage {
class func imageWithColor(color: UIColor) -> UIImage {
let rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)
UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), false, 1.0)
color.setFill()
UIRectFill(rect)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
}

View File

@@ -0,0 +1,31 @@
//
// RoundedImageView.swift
// CapFinder
//
// Created by User on 22.04.18.
// Copyright © 2018 User. All rights reserved.
//
import UIKit
class RoundedImageView: UIImageView {
@IBInspectable var borderColor: UIColor = UIColor.black {
didSet {
layer.borderColor = borderColor.cgColor
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = layer.frame.height / 2
clipsToBounds = true
}
}