Skip to content

Instantly share code, notes, and snippets.

Avatar

Yasmin Benatti yabenatti

View GitHub Profile
View constraintViewController.swift
import UIKit
class ViewController: UIViewController {
let titleLabel: UILabel = {
let label = UILabel()
label.text = "Hello Constraints"
label.backgroundColor = .red
label.translatesAutoresizingMaskIntoConstraints = false
return label
View cartographyConstraint.swift
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
View anchorsconstraints.swift
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
View nslayoutconstraint.swift
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 Sep 26, 2020
Visual Format Constraints
View visualFormat.swift
private func setupVisualConstraints() {
view.addSubview(titleLabel)
view.addSubview(hiButton)
let viewsDict = [
"label": titleLabel,
"button": hiButton
]
let verticalConstraint = NSLayoutConstraint.constraints(
@yabenatti
yabenatti / uFeature.podspec
Created Mar 7, 2019
Example of a podspec
View uFeature.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'
View HelloWorldObjc.m
- (NSString *)getName {
return @"Yasmin Benatti";
}
- (void)helloWorld {
NSLog(@"Hello %@", [self getName]);
}
[self helloWorld];
View helloWorldSwift.swift
func getName() -> String {
return "Yasmin Benatti"
}
func helloWorld() {
print("Hello " + getName())
}
helloWorld()
View TableViewTutorial03.swift
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
}
View TableViewTutorial02.swift
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)
You can’t perform that action at this time.