Skip to content

Instantly share code, notes, and snippets.

View yabenatti's full-sized avatar

Yasmin Benatti yabenatti

  • Sweden
View GitHub Profile
@yabenatti
yabenatti / constraintViewController.swift
Created September 26, 2020 16:11
ConstraintViewController
import UIKit
class ViewController: UIViewController {
let titleLabel: UILabel = {
let label = UILabel()
label.text = "Hello Constraints"
label.backgroundColor = .red
label.translatesAutoresizingMaskIntoConstraints = false
return label
@yabenatti
yabenatti / cartographyConstraint.swift
Created September 26, 2020 16:06
Cartography Constraints
import Cartography
private func setupWithCartography() {
view.addSubview(titleLabel)
view.addSubview(hiButton)
constrain(titleLabel, view) { label, superview in
label.top == superview.top + 20
label.leading == superview.leading + 20
label.trailing == superview.trailing - 20
@yabenatti
yabenatti / anchorsconstraints.swift
Created September 26, 2020 15:45
Anchors Constraints
private func setupAnchorConstraints() {
view.addSubview(titleLabel)
view.addSubview(hiButton)
titleLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
titleLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20).isActive = true
titleLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20).isActive = true
hiButton.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8).isActive = true
hiButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20).isActive = true
@yabenatti
yabenatti / nslayoutconstraint.swift
Created September 26, 2020 15:44
NSLayout Constraints
private func setupNSLayoutConstraints() {
view.addSubview(titleLabel)
view.addSubview(hiButton)
let labelVerticalConstraint = NSLayoutConstraint.init(item: titleLabel, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 20)
let labelLeadingConstraint = NSLayoutConstraint.init(item: titleLabel, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 20)
let labelTrailingConstraint = NSLayoutConstraint.init(item: titleLabel, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: -20)
let buttonVerticalConstraint = NSLayoutConstraint.init(item: hiButton, attribute: .top, relatedBy: .equal, toItem: titleLabel, attribute: .bottom, multiplier: 1, constant: 8)
let buttonLeadingConstraint = NSLayoutConstraint.init(item: hiButton, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 20)
@yabenatti
yabenatti / visualFormat.swift
Last active September 26, 2020 15:43
Visual Format Constraints
private func setupVisualConstraints() {
view.addSubview(titleLabel)
view.addSubview(hiButton)
let viewsDict = [
"label": titleLabel,
"button": hiButton
]
let verticalConstraint = NSLayoutConstraint.constraints(
@yabenatti
yabenatti / uFeature.podspec
Created March 7, 2019 15:45
Example of a podspec
#
# Be sure to run `pod spec lint uFeature.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |s|
s.name = 'uFeature'
@yabenatti
yabenatti / HelloWorldObjc.m
Created January 21, 2019 21:19
HelloWorldObjc
- (NSString *)getName {
return @"Yasmin Benatti";
}
- (void)helloWorld {
NSLog(@"Hello %@", [self getName]);
}
[self helloWorld];
@yabenatti
yabenatti / helloWorldSwift.swift
Created January 21, 2019 21:13
HelloWorldSwift
func getName() -> String {
return "Yasmin Benatti"
}
func helloWorld() {
print("Hello " + getName())
}
helloWorld()
@yabenatti
yabenatti / TableViewTutorial03.swift
Created November 12, 2017 13:01
TableViewTutorial03
extension ViewController : UITableViewDelegate {
//1 - método chamado quando uma linha é selecionada
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
//2 - método para definir a altura de cada linha
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 44
}
@yabenatti
yabenatti / TableViewTutorial02.swift
Created November 12, 2017 12:50
TableViewTutorial02
extension ViewController : UITableViewDataSource {
//1 - primeiro método obrigatório
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
//2 - segundo método obrigatório
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//3 - crie uma célula com o mesmo identificador de quando registramos a classe
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath)