Skip to content

Instantly share code, notes, and snippets.

View josh-marasigan's full-sized avatar

Josh Marasigan josh-marasigan

View GitHub Profile
let frame1 = CGRect(x: 20, y: 250, width: 157.5, height: 157.5)
let view1 = UIView(frame: frame1)
let frame2 = CGRect(x: 197.5, y: 250, width: 157.5, height: 157.5)
let view2 = UIView(frame: frame2)
let view1 = UIView()
view1.backgroundColor = UIColor.systemIndigo
view.addSubview(view1)
view1.snp.makeConstraints { make in
make.top.equalToSuperview().offset(250)
make.leading.equalToSuperview().offset(20)
make.width.height.equalTo(view.snp.width)
NSLayoutConstraint(item: view1, attribute: .leading,
relatedBy: .equal,
toItem: view, attribute: .leading,
multiplier: 1.0,
constant: 20).isActive = true
let view1 = UIView()
view1.backgroundColor = UIColor.systemRed
view1.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(view1)
view1.topAnchor.constraint(equalTo: view.topAnchor,
constant: 250).isActive = true
view1.leadingAnchor.constraint(equalTo: view.leadingAnchor,
@josh-marasigan
josh-marasigan / AddStringAttributeToFoundTextRange.swift
Created May 8, 2020 03:49
`NSMutableAttributedString` extension for adding attributes to found ranges of indicated text within an `NSAttributedString`/`NSMutableAttributedString`
/*
ex.) The following adds an underline attribute to "an example" within "This is an example".
let string = NSMutableAttributedString(string: "This is an example.")
let underlineAttributes: [NSAttributedStringKey : Any] = [
NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle.rawValue
]
string.addAttributeToRange(in: "an example", attributes: underlineAttributes)
// `.` indicates code left out.
// Please refer to the sample app for reference
// https://github.com/josh-marasigan/ObserverDesignExample
class ViewController: UIViewController {
.
.
.
// MARK: - Button Configuration
private func configChangeBackgroundButtonUI() {
.
// `.` indicates code left out.
// Please refer to the sample app for reference
// https://github.com/josh-marasigan/ObserverDesignExample
// Somewhere in the TitleAndTextView.swift file
class TitleAndTextView: UIView {
.
.
.
// MARK: - Class Properties. Fun fact: emojis are just stirng literals
struct ObserverKeys {
static let teal = "observer-example.teal"
static let pink = "observer-example.magenta"
}
@josh-marasigan
josh-marasigan / SwiftMapExercise.swift
Last active April 28, 2018 15:22
Varying Swift syntax for map function
// Most verbose: No compiler assumptions are made, the closure to map
// receives a transforming function explicitly casted as (val: Int) -> Int
// Transforms an array of Int and multiplies each value by 10
arrValues.map({ (val: Int) -> Int in
return val * 10
})
// Compiler assumes return type for closure, no need to explicitly indicate
arrValues.map({ (val: Int) in
return val * 10
let josh = Son()
let joshsMom = Mom(son: josh)
joshsMom.tellJoshWhatToDo()
---
"Washing Dishes"
"Cleaning Room"
"Walking Nala"