Skip to content

Instantly share code, notes, and snippets.

@alexnikol
alexnikol / .swift
Last active April 17, 2020 19:25
Merge NSAtributedStrings
//Way to merge NSAttributedStrings into one string
let mr = "Mr."
let name = "John"
let lastName = "Doe"
let mrString = NSMutableAttributedString(string: mr, attributes: mrAttributes)
let nameString = NSAttributedString(string: name, attributes: nameAttributes)
let lastNameString = NSAttributedString(string: lastName, attributes: lastNameAttributes)
mrString.append(nameString)
mrString.append(lastNameString)
//mrString is a merged result string
@alexnikol
alexnikol / .swift
Created April 17, 2020 19:22
Full Example of Attributed UIlabel
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let mrAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.green, //Text color
.font: UIFont.systemFont(ofSize: 25.0), //Font, Font size
.strikethroughStyle: 3, //Width of strikethrough line
.strikethroughColor: UIColor.red, //Color of strikethrough line
]
@alexnikol
alexnikol / .swift
Last active April 18, 2020 08:30
ColorManager
struct ColorManager {
static let mainRedColor = UIColor(red: 1, green: 0.28, blue: 0.29, alpha: 1)
static let mainWhiteColor = UIColor.white
static let mainBlueColor = UIColor(red: 0.51, green: 0.76, blue: 0.83, alpha: 1)
static let petBorderCellColor = UIColor(red: 0.85, green: 0.93, blue: 0.95, alpha: 1)
static let mainBlueBackground = UIColor(red: 0.9, green: 0.95, blue: 0.96, alpha: 1)
static let mainGrayColor = UIColor.darkGray
static let lightestGrayColor = UIColor(red: 0.85, green: 0.85, blue: 0.83, alpha: 1)
static let btnRedDefault = UIColor(red: 1, green: 0.28, blue: 0.29, alpha: 1)
static let btnRedHighlighted = UIColor(red: 0.9, green: 0.08, blue: 0.09, alpha: 1)
@alexnikol
alexnikol / .swift
Created April 18, 2020 08:45
R.swift usage example
R.font.sfuiDisplayBold(size: 14.0)
R.color.alertBG()
R.nib.authChooseRoleViewController
R.file.configurationPlist()
R.storyboard.launchScreen()
@alexnikol
alexnikol / .swift
Created April 18, 2020 08:52
Convenient swift typealiases for common use
typealias Text = R.string.localizable
typealias Image = R.image
typealias Color = R.color
typealias PlistFetcher = R.file
typealias Font = R.font
@alexnikol
alexnikol / .swift
Last active April 19, 2020 05:27
Swift 4. Open website from iOS Application
guard let url = URL(string: "https://www.google.com/"), //Create non-optional URL to our website
UIApplication.shared.canOpenURL(url) else { //Check if app can open this URL
return
}
UIApplication.shared.open(url) //Open our website in Safari
@alexnikol
alexnikol / .swift
Created April 19, 2020 05:32
Swift 4. Run phone call from iOS Application
let yourNumber = "+1 999 999 9999" //Your needed phone
guard let number = URL(string: "tel://" + yourNumber), //Check if phone non-optional and app can open this URL
UIApplication.shared.canOpenURL(number) else { return }
UIApplication.shared.open(number) //Call your phone
@alexnikol
alexnikol / .swift
Last active April 26, 2020 15:47
Basic properties of UIView
// MARK: Change cornerRadius UIView
view.layer.cornerRadius = 5
// MARK: Set shadow to UIView
view.layer.shadowOffset = CGSize(width: 5, height: 5)
view.layer.shadowOpacity = 0.7
view.layer.shadowRadius = 5
view.layer.shadowColor = UIColor.green.cgColor
// MARK: Set border to UIView
@alexnikol
alexnikol / .swift
Created April 26, 2020 15:53
Method for work with sublayers
var sublayers: [CALayer]? - //Array of all sublayers in current layer
var superlayer: CALayer? - //Parent layer if exist
func addSublayer(CALayer) - //Add new sublayer
func removeFromSuperlayer() - //Remove layer from superLayer
func insertSublayer(CALayer, at: UInt32) - //Insert new layer on specific index
@alexnikol
alexnikol / .swift
Created April 26, 2020 15:57
Add sublayers to layer of UIView
// MARK: Creation of sublayer1
let sublayer1 = CALayer()
sublayer1.frame = CGRect(x: 20, y: 20, width: 30, height: 30)
sublayer1.backgroundColor = UIColor.red.cgColor
// MARK: Creation of sublayer2
let sublayer2 = CALayer()
sublayer2.frame = CGRect(x: 80, y: 80, width: 40, height: 40)
sublayer2.backgroundColor = UIColor.green.cgColor