At the moment i am caught at making an attempt to make the UILabel on the correct facet to not get cutoff since there is a house. I am utilizing stackView in order that i can middle each of the view simply. I considered decoupled the topStack and editButton, however was simply questioning if i may simply stacked each as a substitute
Can give attention to viewDidLoad()
UI
Code
import UIKit
class ProfileViewController: UIViewController {
non-public let profilePicture: UIImageView = {
let picture = UIImageView()
picture.contentMode = .scaleAspectFit
picture.translatesAutoresizingMaskIntoConstraints = false
picture.picture = UIImage(named: "1")
picture.layer.cornerRadius = 50
picture.clipsToBounds = true
return picture
}()
non-public let editButton: UIButton = {
let button = UIButton()
let title = "EDIT PROFILE"
let attributedString = NSAttributedString(string: title, attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 13)])
button.setAttributedTitle(attributedString, for: .regular)
button.setTitleColor(.grey, for: .regular)
button.backgroundColor = .clear
button.layer.borderColor = UIColor.lightGray.cgColor
button.layer.borderWidth = 2.0 // set border width
button.layer.cornerRadius = 20
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, motion: #selector(editButtonTapped), for: .touchUpInside)
return button
}()
non-public func makeTitle(numberTitleStr: String, titleStr: String) -> UIStackView {
let numberTitle = UILabel()
let title = UILabel()
numberTitle.textual content = numberTitleStr
title.textual content = titleStr
numberTitle.font = UIFont.systemFont(ofSize: 14, weight: .daring)
numberTitle.textColor = .black
title.font = UIFont.systemFont(ofSize: 14, weight: .medium)
title.textColor = .grey
let stackView = UIStackView(arrangedSubviews: [numberTitle, title])
stackView.alignment = .main
stackView.axis = .horizontal
stackView.spacing = 5
return stackView
}
@objc func editButtonTapped() {
print("Instance")
}
func setupNavigation() {
navigationItem.title = "Profile"
let look = UINavigationBarAppearance()
look.configureWithOpaqueBackground()
look.backgroundColor = .lightGray
let titleAttribute = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16, weight: .semibold), NSAttributedString.Key.foregroundColor: UIColor.black]
look.titleTextAttributes = titleAttribute
navigationController?.navigationBar.standardAppearance = look
navigationController?.navigationBar.scrollEdgeAppearance = look
}
override func viewDidLoad() {
tremendous.viewDidLoad()
setupNavigation()
let friendsStackView = makeTitle(numberTitleStr: "0", titleStr: "mates")
let matchesStackView = makeTitle(numberTitleStr: "0", titleStr: "matches")
let topStack = UIStackView(arrangedSubviews: [friendsStackView, matchesStackView])
topStack.translatesAutoresizingMaskIntoConstraints = false
topStack.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
topStack.axis = .horizontal
topStack.distribution = .equalCentering
topStack.spacing = 5
let mainStack = UIStackView(arrangedSubviews: [topStack, editButton])
mainStack.translatesAutoresizingMaskIntoConstraints = false
mainStack.axis = .vertical
mainStack.spacing = 10
view.backgroundColor = .white
view.addSubview(profilePicture)
view.addSubview(mainStack)
// view.addSubview(topStack)
// view.addSubview(editButton)
NSLayoutConstraint.activate([
profilePicture.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20),
profilePicture.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
profilePicture.widthAnchor.constraint(equalToConstant: 100),
profilePicture.heightAnchor.constraint(equalToConstant: 100),
mainStack.leadingAnchor.constraint(equalTo: profilePicture.trailingAnchor, constant: 30),
mainStack.centerYAnchor.constraint(equalTo: profilePicture.centerYAnchor),
editButton.heightAnchor.constraint(equalToConstant: 40),
editButton.widthAnchor.constraint(equalToConstant: 120),
// topStack.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 35),
// topStack.leadingAnchor.constraint(equalTo: profilePicture.trailingAnchor, constant: 20),
// editButton.topAnchor.constraint(equalTo: topStack.topAnchor, constant: 25),
// editButton.leadingAnchor.constraint(equalTo: profilePicture.trailingAnchor, constant: 20),
])
}
}