13.1. Integrating Photo Pickers
Updating RegisterView.swift
//
// RegisterView.swift
// App12
//
// Created by Sakib Miazi on 6/2/23.
//
import UIKit
class RegisterView: UIView {
//codes omitted...
var labelPhoto:UILabel!
var buttonTakePhoto: UIButton!
//codes omitted...
override init(frame: CGRect){
super.init(frame: frame)
self.backgroundColor = .white
//codes omitted...
setuplabelPhoto()
setupbuttonTakePhoto()
//codes omitted...
initConstraints()
}
//codes omitted...
func setuplabelPhoto(){
labelPhoto = UILabel()
labelPhoto.text = "Add Profile Photo"
labelPhoto.font = UIFont.boldSystemFont(ofSize: 14)
labelPhoto.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(labelPhoto)
}
func setupbuttonTakePhoto(){
buttonTakePhoto = UIButton(type: .system)
buttonTakePhoto.setTitle("", for: .normal)
buttonTakePhoto.setImage(UIImage(systemName: "camera.fill")?.withRenderingMode(.alwaysOriginal), for: .normal)
//buttonTakePhoto.setImage(UIImage(systemName: "camera.fill")?.withRenderingMode(.alwaysOriginal), for: .normal)
buttonTakePhoto.contentHorizontalAlignment = .fill
buttonTakePhoto.contentVerticalAlignment = .fill
buttonTakePhoto.imageView?.contentMode = .scaleAspectFit
buttonTakePhoto.showsMenuAsPrimaryAction = true
buttonTakePhoto.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(buttonTakePhoto)
}
//codes omitted...
func initConstraints(){
NSLayoutConstraint.activate([
textFieldName.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor, constant: 32),
textFieldName.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor),
textFieldName.widthAnchor.constraint(equalTo: self.safeAreaLayoutGuide.widthAnchor, multiplier: 0.9),
textFieldEmail.topAnchor.constraint(equalTo: textFieldName.bottomAnchor, constant: 16),
textFieldEmail.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor),
textFieldEmail.widthAnchor.constraint(equalTo: self.safeAreaLayoutGuide.widthAnchor, multiplier: 0.9),
textFieldPassword.topAnchor.constraint(equalTo: textFieldEmail.bottomAnchor, constant: 16),
textFieldPassword.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor),
textFieldPassword.widthAnchor.constraint(equalTo: self.safeAreaLayoutGuide.widthAnchor, multiplier: 0.9),
buttonTakePhoto.topAnchor.constraint(equalTo: textFieldPassword.bottomAnchor, constant: 16),
buttonTakePhoto.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor),
//MARK: setting buttonTakePhoto's height and width..
buttonTakePhoto.widthAnchor.constraint(equalToConstant: 100),
buttonTakePhoto.heightAnchor.constraint(equalToConstant: 100),
labelPhoto.topAnchor.constraint(equalTo: buttonTakePhoto.bottomAnchor),
labelPhoto.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor),
buttonRegister.topAnchor.constraint(equalTo: labelPhoto.bottomAnchor, constant: 32),
buttonRegister.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor)
])
}
//codes omitted...
}
Patching RegisterViewController to Pick Photo
PhotoManager.swift

Last updated