Skip to content

Instantly share code, notes, and snippets.

@ayoub-9
Created December 1, 2018 15:17
Show Gist options
  • Select an option

  • Save ayoub-9/512b9f59994429506704bd00cb7bd60b to your computer and use it in GitHub Desktop.

Select an option

Save ayoub-9/512b9f59994429506704bd00cb7bd60b to your computer and use it in GitHub Desktop.
background Custom 1
-----------------------
let backgroundImageView = UIImageView()
func setBackground() {
view.addSubview(backgroundImageView)
backgroundImageView.translatesAutoresizingMaskIntoConstraints = false
backgroundImageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
backgroundImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
backgroundImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
backgroundImageView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
backgroundImageView.image = UIImage(named: "background-wave")
view.sendSubviewToBack(backgroundImageView)
}
}
---------------------------------
TextFiled Custom 2
---------------------------------
1 Create File Swift named SATextField.swift
import UIKit
class SATextField: UITextField {
override init(frame: CGRect) {
super.init(frame: frame)
setUpField()
}
required init?(coder aDecoder: NSCoder) {
super.init( coder: aDecoder )
setUpField()
}
private func setUpField() {
tintColor = .white
textColor = .darkGray
font = UIFont(name: Fonts.avenirNextCondensedDemiBold, size: 18)
backgroundColor = UIColor(white: 1.0, alpha: 0.5)
autocorrectionType = .no
layer.cornerRadius = 25.0
clipsToBounds = true
let placeholder = self.placeholder != nil ? self.placeholder! : ""
let placeholderFont = UIFont(name: Fonts.avenirNextCondensedDemiBold, size: 18)!
attributedPlaceholder = NSAttributedString(string: placeholder, attributes:
[NSAttributedString.Key.foregroundColor: UIColor.lightGray,
NSAttributedString.Key.font: placeholderFont])
let indentView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
leftView = indentView
leftViewMode = .always
}
}
----------------------------------------------
Button Custom 3
----------------------
1 Create File Swift named SAButton.swift
import UIKit
class SAButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
setupButton()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupButton()
}
private func setupButton() {
backgroundColor = Colors.tropicBlue
titleLabel?.font = UIFont(name: Fonts.avenirNextCondensedDemiBold, size: 22)
layer.cornerRadius = frame.size.height/2
setTitleColor(.white, for: .normal)
}
}
@ayoub-9
Copy link
Author

ayoub-9 commented Dec 1, 2018

3 Create File named Constants.swift and add the code

struct Colors {
static let tropicBlue = UIColor(red: 0, green: 192/255, blue: 255/255, alpha: 1)
}

struct Fonts {
static let avenirNextCondensedDemiBold = "AvenirNextCondensed-DemiBold"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment