Skip to content

Instantly share code, notes, and snippets.

View badrinathvm's full-sized avatar

Badarinath Venkatnarayansetty badrinathvm

View GitHub Profile
@badrinathvm
badrinathvm / DynamicHeight.swift
Created July 26, 2019 17:56
dynamic height of the collectionView
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let height = calculateDynamicHeightOftheCell(index: indexPath.row)
return CGSize(width: self.collectionView.bounds.width, height: height)
}
/**
Calculates the height of the card based on the content inside the view.
- parameters:
- index = identifies which cell it is.
*/
@badrinathvm
badrinathvm / Container.swift
Last active September 2, 2019 05:00
Setting up Container View Controller
func setupContainerView() {
[containerVC,notchVC].forEach { (viewController) in
self.view.addSubview(viewController.view)
}
heightConstraint = containerVC.view.heightAnchor.constraint(equalToConstant: 0)
notchBottomConstraint = notchVC.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
NSLayoutConstraint.activate([
containerVC.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
containerVC.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
@badrinathvm
badrinathvm / AddBlurEffectView.swift
Last active September 2, 2019 18:09
Adding a blur Effect View
let blurredEffectView:UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .dark)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.translatesAutoresizingMaskIntoConstraints = false
return blurredEffectView
}()
func setupBlurView() {
self.view.addSubview(blurredEffectView)
@badrinathvm
badrinathvm / Animate.swift
Created September 2, 2019 05:06
Animate by considering the height Constraint
func animate() {
let screenSize = UIScreen.main.bounds
let heightValue = screenSize.size.height / 2
self.view.layoutIfNeeded()
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.notchBottomConstraint.constant = -heightValue
self.heightConstraint.constant = heightValue
self.view.layoutIfNeeded()
}, completion: nil)
}
fileprivate func performAnimation() {
let screenSize = UIScreen.main.bounds
let stackedButtons = self.buttonStackView.arrangedSubviews
let animation = UIViewPropertyAnimator(duration: 0.3, curve: .easeOut) {
//hide or show the stackview.
self.buttonStackView.isHidden = self.buttonsAreHidden
@badrinathvm
badrinathvm / CustomPath.swift
Created September 8, 2019 06:48
Add a custom path
func customPath() -> UIBezierPath {
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 200))
let endPoint = CGPoint(x: 500, y: 200)
let randomYShift = 200 + drand48() * 300
let cp1 = CGPoint(x: 100, y: 100 - randomYShift)
let cp2 = CGPoint(x: 200, y: 100 + randomYShift + 400)
@badrinathvm
badrinathvm / AnimateParticlesWithCustomPath.swift
Created September 8, 2019 09:25
Animate Particles With Custom Path
import UIKit
class ViewController: UIViewController {
let width: CGFloat = 240.0
let height: CGFloat = 160.0
override func viewDidLoad() {
super.viewDidLoad()
let sineView = HingeView(frame: UIScreen.main.bounds)
sineView.backgroundColor = .yellow
@badrinathvm
badrinathvm / CircularShapes.swift
Created November 9, 2019 17:45
Text Not expanding it's size when placed inside ScrollView
import Foundation
import SwiftUI
struct MoreCircleShapes: View {
var body: some View {
VStack(spacing: 10) {
Circle().fill(Color.purple).frame(height: 100).padding()
Text("Note : Fill Modifier apples specifically to shapes nopt a view.")
.frame(maxWidth: .infinity)
@badrinathvm
badrinathvm / sample.json
Created November 13, 2019 17:08
JSON Sample
{
"user": {
"type": "lead",
"id": 146179,
"name": "Rubamaga",
"email": "rubamaga@example.com",
"user_id": "22449",
"phone": null,
"created_at": 1506500350,
"signed_up_at": null,
@available(iOS 13.0, *)
struct SwiftUIView: View {
var body: some View {
VStack {
Text("Welcome to SwiftUI")
.padding()
.font(.system(size: 15))
Spacer()
}