Programmatic UIButton Constraints Not Working - ios

I'm building a view programmatically where a blue button is supposed to be laid out in the center of the screen under a user image, but it's getting constrained to the top left corner every time. I have self.translatesAutoresizingMaskIntoConstraints set to false in the init method of this view. Here is my code where I restrain this button:
addSubview(continueMessagingButton)
continueMessagingButton.anchor(top: currentUserImage.bottomAnchor, leading: leadingAnchor, bottom: nil, trailing: trailingAnchor, padding: .init(top: 32, left: 48, bottom: 0, right: 48), size: .init(width: 0, height: 60))
continueMessagingButton.layer.cornerRadius = 30
Here is an image of what's happening:
Please help thank you!
full code:
import UIKit
import FirebaseCore
import FirebaseAuth
import FirebaseDatabase
import FirebaseStorage
import FirebaseAnalytics
class MatchView: UIView {
var userId: String! {
didSet {
API.User.observeCurrentUser { (user) in
self.currentUserImage.sd_setImage(with: URL(string:
user.profileImages!.first!))
self.currentUserImage.alpha = 1
}
API.User.observeUsers(withId: userId) { (user) in
self.otherUserImage.sd_setImage(with: URL(string:
user.profileImages!.first!))
self.otherUserImage.alpha = 1
}
}
}
let partyPopperImage: UIImageView = {
let imageView = UIImageView(image: #imageLiteral(resourceName:
"party-popper-emoji"))
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
return imageView
}()
var username: String! {
didSet {
descriptionLabel.text = "Congratulations!\n\(username!) is
interested in you!"
}
}
let descriptionLabel: UILabel = {
let label = UILabel()
label.text = ""
label.lineBreakMode = .byWordWrapping
label.textAlignment = .center
label.textColor = #colorLiteral(red: 0.08732911403, green:
0.7221731267, blue: 1, alpha: 1)
label.font = UIFont(name: "Avenir-Medium", size: 19)
label.numberOfLines = 0
return label
}()
let currentUserImage: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.layer.borderWidth = 2
imageView.layer.borderColor = #colorLiteral(red: 0.08732911403,
green: 0.7221731267, blue: 1, alpha: 1)
imageView.alpha = 0
return imageView
}()
let otherUserImage: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.layer.borderWidth = 2
imageView.layer.borderColor = #colorLiteral(red: 0.08732911403,
green: 0.7221731267, blue: 1, alpha: 1)
imageView.alpha = 0
return imageView
}()
let continueMessagingButton: UIButton = {
let button = GlympsGradientButton(type: .system)
button.setTitle("CONTINUE MESSAGING", for: .normal)
button.setTitleColor(#colorLiteral(red: 1, green: 1, blue: 1,
alpha: 1), for: .normal)
button.backgroundColor = #colorLiteral(red: 0.08732911403, green: 0.7221731267, blue: 1, alpha: 1)
button.clipsToBounds = true
return button
}()
let messageLaterButton: UIButton = {
let button = GlympsGradientBorderButton(type: .system)
button.setTitle("Message Later", for: .normal)
button.setTitleColor(#colorLiteral(red: 0.08732911403, green:
0.7221731267, blue: 1, alpha: 1), for: .normal)
button.clipsToBounds = true
button.backgroundColor = .clear
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
continueMessagingButton.translatesAutoresizingMaskIntoConstraints =
true
setupBlurView()
setupLayout()
//setupAnimations()
let tap = UIGestureRecognizer(target: self, action:
#selector(handleDismiss))
self.addGestureRecognizer(tap)
}
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style:
.light))
func setupAnimations() {
let angle = 30 * CGFloat.pi / 180
currentUserImage.transform = CGAffineTransform(rotationAngle: -
angle).concatenating(CGAffineTransform(translationX: 200, y: 0))
otherUserImage.transform = CGAffineTransform(rotationAngle:
angle).concatenating(CGAffineTransform(translationX: -200, y: 0))
continueMessagingButton.transform = CGAffineTransform(translationX:
-500, y: 0)
messageLaterButton.transform = CGAffineTransform(translationX: 500,
y: 0)
UIView.animateKeyframes(withDuration: 1.3, delay: 0, options:
.calculationModeCubic, animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration:
0.45, animations: {
self.currentUserImage.transform =
CGAffineTransform(rotationAngle: -angle)
self.otherUserImage.transform =
CGAffineTransform(rotationAngle: angle)
})
UIView.addKeyframe(withRelativeStartTime: 0.8,
relativeDuration: 0.5, animations: {
self.currentUserImage.transform = .identity
self.otherUserImage.transform = .identity
})
}) { (_) in
}
UIView.animate(withDuration: 0.75, delay: 0.6 * 1.3,
usingSpringWithDamping: 0.5, initialSpringVelocity: 0.1, options:
.curveEaseOut, animations: {
self.continueMessagingButton.transform = .identity
self.messageLaterButton.transform = .identity
})
}
func setupLayout() {
addSubview(partyPopperImage)
addSubview(descriptionLabel)
addSubview(currentUserImage)
addSubview(otherUserImage)
addSubview(continueMessagingButton)
//addSubview(messageLaterButton)
partyPopperImage.anchor(top: nil, leading: nil, bottom:
descriptionLabel.topAnchor, trailing: nil, padding: .init(top: 0, left:
0, bottom: 16, right: 0), size: .init(width: 150, height: 150))
partyPopperImage.centerXAnchor.constraint(equalTo:
self.centerXAnchor).isActive = true
descriptionLabel.anchor(top: nil, leading: self.leadingAnchor,
bottom: currentUserImage.topAnchor, trailing: trailingAnchor, padding:
.init(top: 0, left: 0, bottom: 32, right: 0), size: .init(width: 0,
height: 80))
currentUserImage.anchor(top: nil, leading: nil, bottom: nil,
trailing: centerXAnchor, padding: .init(top: 0, left: 0, bottom: 0,
right: 16), size: .init(width: 140, height: 140))
currentUserImage.layer.cornerRadius = 70
currentUserImage.centerYAnchor.constraint(equalTo:
centerYAnchor).isActive = true
otherUserImage.anchor(top: nil, leading: centerXAnchor, bottom:
nil, trailing: nil, padding: .init(top: 0, left: 16, bottom: 0, right:
0), size: .init(width: 140, height: 140))
otherUserImage.layer.cornerRadius = 70
otherUserImage.centerYAnchor.constraint(equalTo:
centerYAnchor).isActive = true
continueMessagingButton.anchor(top: currentUserImage.bottomAnchor,
leading: leadingAnchor, bottom: nil, trailing: trailingAnchor, padding:
.init(top: 32, left: 48, bottom: 0, right: 48), size: .init(width: 0,
height: 60))
continueMessagingButton.layer.cornerRadius = 30
// messageLaterButton.anchor(top:
continueMessagingButton.bottomAnchor, leading:
continueMessagingButton.leadingAnchor, bottom: nil, trailing:
continueMessagingButton.trailingAnchor, padding: .init(top: 16, left:
0, bottom: 0, right: 0), size: .init(width: 0, height: 60))
// messageLaterButton.layer.cornerRadius = 30
self.layoutIfNeeded()
}
func setupBlurView() {
addSubview(visualEffectView)
visualEffectView.fillSuperview()
visualEffectView.alpha = 0
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping:
1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.visualEffectView.alpha = 1
}) { (_) in
}
}
#objc func handleDismiss() {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping:
1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.alpha = 0
}) { (_) in
self.removeFromSuperview()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

I've figured out the issue. For my gradient colors I had:
let leftColor = UIColor.blue
let rightColor = UIColor.green
gradientLayer.colors = [leftColor, rightColor]
Once I added .cgColor to the ends of these, it worked:
gradientLayer.colors = [leftColor.cgColor, rightColor.cgColor]
Super minor, but this fixed the gradient!
I also needed to change the frame from
self.frame
to
gradientLayer.frame
Also minor, but this fixed the button location.

Related

UIButton shadow and lighting effect (Swift 4)

I'd like to add a lighting effect like these two buttons, a shadow on the bottom but also a lighted edge on top as if there were a light above it.
I've been experimenting with :
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowColor.layer.shadowOffset = CGSize(width: 2, height: 2)
button.layer.shadowColor.layer.shadowRadius = 2
button.layer.shadowColor.layer.shadowOpacity = 8
button.layer.shadowColor.layer.masksToBounds = false
and get a nice shadow on the bottom, but how would I light up the top edge?
I was able to get a button pretty similar to your first drawing, just as an experiment:
The button background is constructed entirely using elementary drawing commands involving UIBezierPath and CGContext in a UIGraphicsImageRenderer. So if that's an acceptable sort of approach, you could just do a tweak on the sort of thing I'm doing.
let r = UIGraphicsImageRenderer(size: CGSize(width:100, height:100))
let im = r.image {
ctx in let con = ctx.cgContext
do {
let p = UIBezierPath(roundedRect: CGRect.init(x: 0, y: 0, width: 100, height: 50), cornerRadius: 10)
UIColor(white: 0.9, alpha: 1.0).setFill()
p.fill()
}
do {
let p = UIBezierPath(roundedRect: CGRect.init(x: 0, y: 50, width: 100, height: 50), cornerRadius: 10)
UIColor(white: 0.1, alpha: 1.0).setFill()
p.fill()
}
do {
let p = UIBezierPath(roundedRect: CGRect.init(x: 0, y: 2, width: 100, height: 95), cornerRadius: 10)
p.addClip()
}
let locs : [CGFloat] = [ 0.0, 0.2, 0.8, 1.0 ]
let colors : [CGFloat] = [
0.54, 0.54, 0.54, 1.0,
0.5, 0.5, 0.5, 1.0,
0.5, 0.5, 0.5, 1.0,
0.44, 0.44, 0.44, 1.0,
]
let sp = CGColorSpaceCreateDeviceRGB()
let grad = CGGradient(
colorSpace:sp, colorComponents: colors, locations: locs, count: 4)!
con.drawLinearGradient(grad,
start: CGPoint(x:0,y:0), end: CGPoint(x:0,y:100), options:[])
}
let b = UIButton(type: .custom)
b.setTitle("9", for: .normal)
b.setBackgroundImage(im, for: .normal)
b.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
b.titleLabel?.font = UIFont.systemFont(ofSize: 40, weight: .bold)
self.view.addSubview(b)
b.layer.borderWidth = 1
b.layer.borderColor = UIColor.black.cgColor
b.layer.cornerRadius = 10

Change text of UILabel from outside of function

Once my UIButton is pressed, I want to change the text of my UILabels. Right now when the button is pressed it transitions to a new ViewController with the same background and same theme, just with different text. I figure it is not the best approach. I cannot access my UILables outside of my function setUpView(). What is the best approach to do this.
#objc func buttonTapped(_ sender: UIButton){
//this is where I will change my text. myLabel.text = "new text"
let modalViewController = PageTwoViewController()
modalViewController.modalPresentationStyle = .overCurrentContext
present(modalViewController, animated: false)
}
func setUpView(){
let headerView = UIView()
headerView.backgroundColor = UIColor.rgb(red: 235, green: 248, blue: 242)
view.addSubview(headerView)
headerView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 150, paddingLeft: 20, paddingBottom: 150, paddingRight: 20, width: 0, height: 0)
let myLabel = UILabel()
myLabel.text = "Rate your xxxxx"
myLabel.textColor = UIColor.rgb(red: 0, green: 48, blue: 51)
myLabel.textAlignment = .left
myLabel.numberOfLines = 0
headerView.addSubview(myLabel)
myLabel.font = .systemFont(ofSize: 32)
myLabel.anchor(top: headerView.topAnchor, left: headerView.leftAnchor, bottom: nil, right: headerView.rightAnchor, paddingTop: 150, paddingLeft: 30, paddingBottom: 0, paddingRight: 40, width: 0, height: 0)
let steps = UILabel()
steps.text = "1 of 3"
steps.textColor = UIColor.rgb(red: 0, green: 48, blue: 51)
headerView.addSubview(steps)
steps.font = .systemFont(ofSize: 14)
headerView.addSubview(steps)
steps.anchor(top: nil, left: headerView.leftAnchor, bottom: myLabel.topAnchor, right: nil, paddingTop: 0, paddingLeft: 30, paddingBottom: 10, paddingRight: 0, width: 0, height: 0)
let button = UIButton(type: .system)
button.setTitle("Next", for: .normal)
button.layer.cornerRadius = 30
button.backgroundColor = UIColor.white
button.setTitleColor(UIColor.rgb(red: 0, green: 48, blue: 51), for: .normal)
button.layer.borderWidth = 1.7
button.layer.borderColor = UIColor.black.cgColor
button.titleLabel?.font = UIFont.systemFont(ofSize: 20)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
headerView.addSubview(button)
button.anchor(top: nil, left: headerView.leftAnchor, bottom: headerView.bottomAnchor, right: headerView.rightAnchor, paddingTop: 0, paddingLeft: 25, paddingBottom: 30, paddingRight: 25, width: 0, height: 60)
}
override func viewDidLoad() {
setUpView()
super.viewDidLoad()
}
You have to declare the variables globally and then change the text.
class TestViewController: UIViewController {
private var myButton : UIButton = {
let button = UIButton()
button.backgroundColor = .red
return button
}()
private var myLabel: UILabel = {
let label = UILabel()
return label
}()
func setupView() {
myButton.setTitle("My Button", .normal) //You can do it like this
myLabel.text = "This is my text"
}
}
You can declare your labels globally in your view controller and then you can use any where in view controller as follow:
let myLabel: UILabel = {
let label = UILabel()
return label
}()

Swift CollectionViewCell has different frame than its CollectionView

I have a CollectionView which has fills the whole screen, has horizontal scrollDirection and is paging enabled. It is inside of a NavigationController with a hidden navigationBar. The CollectionViewCells have the height of the screen too.
What I would expect to happen:
Each cell fills the whole screen and when I swipe to left/right another cell appears and fills the whole screen.
What actually happens:
The cells are not filling the whole screen. There is a little space (approx. 20 pxl) between the top of the cells and the top border of the screen. Also the bottom of the cell (also approx. 20 pxl) is "under" the bottom border of the screen.
Also i get a warning:
The behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
So the cells height is correct as it seems, but the y-value is wrong.
What I already tried:
override shouldInvalidateLayoutForBoundsChange to return true.
As you can see here the blue border is the border of the collectionView and the red border is the border of the cell. The blue border is, as I would expect it, but I would expect the red border to be like the blue border.
Here is the code:
class LoginController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, LoginControllerDelegate, UIGestureRecognizerDelegate {
lazy var loginCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 0
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.dataSource = self
cv.delegate = self
cv.isPagingEnabled = true
cv.layer.borderWidth = 1.0
cv.layer.borderColor = UIColor.blue.cgColor
return cv
}()
let introCellId = "IntroCellId"
let loginCellId = "LoginCellId"
let pages: [Page] = {
let firstPage = Page(title: String,
message: String,
imageName: String)
let secondPage = Page(title: String,
message: String,
imageName: String)
let thirdPage = Page(title: String,
message: String,
imageName: String)
return [firstPage, secondPage, thirdPage]
}()
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.isHidden = true
view.addSubview(loginCollectionView)
registerCells()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return pages.count + 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == pages.count {
let loginCell = collectionView.dequeueReusableCell(withReuseIdentifier: loginCellId, for: indexPath) as! LoginCell
loginCell.loginControllerDelegate = self
loginCell.layer.borderColor = UIColor.red.cgColor
loginCell.layer.borderWidth = 2.0
return loginCell
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: introCellId, for: indexPath) as! PageCell
let page = pages[indexPath.item]
cell.page = page
cell.layer.borderColor = UIColor.red.cgColor
cell.layer.borderWidth = 2.0
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: self.loginCollectionView.frame.width, height: self.loginCollectionView.frame.height)
}
}
PageCell:
class PageCell: UICollectionViewCell {
var page: Page? {
didSet {
guard let page = page
else {
return
}
imageView.image = UIImage(named: page.imageName)
let color = UIColor(white: 0.2, alpha: 1)
let attributedText = NSMutableAttributedString(string: page.title, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium), NSAttributedString.Key.foregroundColor: color])
attributedText.append(NSMutableAttributedString(string: "\n\n\(page.message)", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium), NSAttributedString.Key.foregroundColor: color]))
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
let length = attributedText.string.count
attributedText.addAttributes([NSAttributedString.Key.paragraphStyle: paragraphStyle], range: NSRange(location: 0, length: length))
textView.attributedText = attributedText
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
let imageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFill
iv.backgroundColor = UIColor(displayP3Red: 139/255, green: 221/255, blue: 116/255, alpha: 1)
iv.clipsToBounds = true
return iv
}()
let textView: UITextView = {
let tv = UITextView()
tv.isEditable = false
tv.contentInset = UIEdgeInsets(top: 24, left: 0, bottom: 0, right: 0)
tv.textColor = UIColor(displayP3Red: 51/255, green: 51/255, blue: 51/255, alpha: 1)
return tv
}()
func setupViews() {
addSubview(imageView)
addSubview(textView)
_ = imageView.anchor(topAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: screenWidth, heightConstant: (screenHeight) / 2)
_ = textView.anchor(imageView.bottomAnchor, left: leftAnchor, bottom: bottomAnchor, right: rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: screenWidth, heightConstant: (screenHeight) / 2)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been impremented")
}
}
LoginCell:
class LoginCell: UICollectionViewCell {
let logoImageView: UIImageView = {
let image = UIImage(named: "logo green")
let imageView = UIImageView(image: image)
return imageView
}()
let emailTextField: UITextField = {
let textField = UITextField()
textField.placeholder = "E-Mail"
textField.layer.borderColor = UIColor.lightGray.cgColor
let border = CALayer()
border.frame = CGRect(x: 0, y: 40, width: UIScreen.main.bounds.width - 64, height: 2.0)
border.backgroundColor = UIColor(displayP3Red: 51/255, green: 51/255, blue: 51/255, alpha: 1).cgColor
textField.layer.addSublayer(border)
textField.keyboardType = .emailAddress
return textField
}()
let emailAlertLabel: UILabel = {
let label = UILabel()
label.text = "E-Mail-Adresse nicht gefunden"
label.textColor = .red
label.isHidden = true
return label
}()
let passwordTextField: UITextField = {
let textField = UITextField()
textField.placeholder = "Passwort"
textField.layer.borderColor = UIColor.lightGray.cgColor
let border = CALayer()
border.frame = CGRect(x: 0, y: 40, width: UIScreen.main.bounds.width - 64, height: 2.0)
border.backgroundColor = UIColor(displayP3Red: 51/255, green: 51/255, blue: 51/255, alpha: 1).cgColor
textField.layer.addSublayer(border)
textField.isSecureTextEntry = true
return textField
}()
let passwordAlertLabel: UILabel = {
let label = UILabel()
label.text = "Ungültiges Passwort"
label.textColor = .red
label.isHidden = true
return label
}()
lazy var forgotPasswordButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = .white
button.setTitle("Passwort vergessen?", for: .normal)
button.setTitleColor(UIColor(displayP3Red: 139/255, green: 221/255, blue: 116/255, alpha: 1), for: .normal)
button.addTarget(self, action: #selector(handleForgotPassword), for: .touchUpInside)
button.contentHorizontalAlignment = .left
return button
}()
lazy var loginButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = UIColor(displayP3Red: 139/255, green: 221/255, blue: 116/255, alpha: 1)
button.setTitle("Login", for: .normal)
button.setTitleColor(.white, for: .normal)
button.addTarget(self, action: #selector(checkUserData), for: .touchUpInside)
button.layer.cornerRadius = 25.0
return button
}()
weak var loginControllerDelegate: LoginControllerDelegate?
lazy var stayLoggedInSwitch: UISwitch = {
let loginSwitch = UISwitch(frame: CGRect(x: 150, y: 150, width: 0, height: 0))
loginSwitch.addTarget(self, action: #selector(LoginCell.handleStayLoggedInState(_:)), for: .valueChanged)
loginSwitch.setOn(false, animated: true)
return loginSwitch
}()
let stayLoggedInTextField: UITextField = {
let textField = UITextField()
textField.text = "Angemeldet bleiben"
textField.textColor = UIColor(displayP3Red: 51/255, green: 51/255, blue: 51/255, alpha: 1)
textField.isUserInteractionEnabled = false
return textField
}()
let registerLabel: UILabel = {
let label = UILabel()
label.text = "Sie haben noch keinen Account?"
label.textColor = .lightGray
label.backgroundColor = .white
label.font = label.font.withSize(13)
return label
}()
lazy var registerButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = .white
button.setTitle("Registrieren", for: .normal)
button.setTitleColor(UIColor(displayP3Red: 139/255, green: 221/255, blue: 116/255, alpha: 1), for: .normal)
button.addTarget(self, action: #selector(handleRegister), for: .touchUpInside)
button.contentHorizontalAlignment = .left
button.titleLabel?.font = button.titleLabel?.font.withSize(13)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
func setupViews() {
addSubview(logoImageView)
addSubview(emailTextField)
addSubview(emailAlertLabel)
addSubview(passwordTextField)
addSubview(passwordAlertLabel)
addSubview(forgotPasswordButton)
addSubview(loginButton)
addSubview(stayLoggedInSwitch)
addSubview(stayLoggedInTextField)
addSubview(registerLabel)
addSubview(registerButton)
_ = logoImageView.anchor(centerYAnchor, left: nil, bottom: nil, right: nil, topConstant: -230, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 160, heightConstant: 160)
logoImageView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
_ = emailTextField.anchor(logoImageView.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 35, leftConstant: 32, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 50)
_ = emailAlertLabel.anchor(emailTextField.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 0, leftConstant: 32, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 20)
_ = passwordTextField.anchor(emailAlertLabel.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 0, leftConstant: 32, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 50)
_ = passwordAlertLabel.anchor(passwordTextField.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 0, leftConstant: 32, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 20)
_ = forgotPasswordButton.anchor(passwordAlertLabel.bottomAnchor, left: leftAnchor, bottom: nil, right: nil, topConstant: 0, leftConstant: 32, bottomConstant: 0, rightConstant: 0, widthConstant: 200, heightConstant: 25)
_ = loginButton.anchor(forgotPasswordButton.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 4, leftConstant: 32, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 50)
_ = stayLoggedInSwitch.anchor(loginButton.bottomAnchor, left: leftAnchor, bottom: nil, right: nil, topConstant: 16, leftConstant: 32, bottomConstant: 0, rightConstant: 0, widthConstant: 60, heightConstant: 50)
_ = stayLoggedInTextField.anchor(loginButton.bottomAnchor, left: stayLoggedInSwitch.rightAnchor, bottom: nil, right: rightAnchor, topConstant: 16, leftConstant: 0, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 32)
_ = registerLabel.anchor(nil, left: leftAnchor, bottom: bottomAnchor, right: nil, topConstant: 0, leftConstant: 32, bottomConstant: 32, rightConstant: 0, widthConstant: 200, heightConstant: 25)
_ = registerButton.anchor(nil, left: registerLabel.rightAnchor, bottom: bottomAnchor, right: rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 32, rightConstant: 32, widthConstant: 0, heightConstant: 25)
emailTextField.addTarget(self, action: #selector(underlineTextFieldColor(sender:)), for: .editingDidBegin)
emailTextField.addTarget(self, action: #selector(underlineTextFieldDark(sender:)), for: .editingDidEnd)
passwordTextField.addTarget(self, action: #selector(underlineTextFieldColor(sender:)), for: .editingDidBegin)
passwordTextField.addTarget(self, action: #selector(underlineTextFieldDark(sender:)), for: .editingDidEnd)
}
#objc func underlineTextFieldDark(sender: UITextField) {
sender.layer.sublayers![0].backgroundColor = UIColor(displayP3Red: 51/255, green: 51/255, blue: 51/255, alpha: 1).cgColor
}
#objc func underlineTextFieldColor(sender: UITextField) {
sender.layer.sublayers![0].backgroundColor = UIColor(displayP3Red: 139/255, green: 221/255, blue: 116/255, alpha: 1).cgColor
}
#objc func handleLogin() {
loginControllerDelegate?.finishLoggingIn()
}
#objc func handleStayLoggedInState(_ sender: UISwitch) {
if (sender.isOn == true) {
UserDefaults.standard.setIsLoggedIn(value: true)
}
else {
UserDefaults.standard.setIsLoggedIn(value: false)
}
}
#objc func handleForgotPassword() {
loginControllerDelegate?.finishLoggingIn()
}
#objc func handleRegister() {
loginControllerDelegate?.finishLoggingIn()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
The Anchor method:
extension UIView {
func anchor(_ top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, topConstant: CGFloat = 0, leftConstant: CGFloat = 0, bottomConstant: CGFloat = 0, rightConstant: CGFloat = 0, widthConstant: CGFloat = 0, heightConstant: CGFloat = 0) -> [NSLayoutConstraint] {
translatesAutoresizingMaskIntoConstraints = false
var anchors = [NSLayoutConstraint]()
if let top = top {
anchors.append(topAnchor.constraint(equalTo: top, constant: topConstant))
}
if let left = left {
anchors.append(leftAnchor.constraint(equalTo: left, constant: leftConstant))
}
if let bottom = bottom {
anchors.append(bottomAnchor.constraint(equalTo: bottom, constant: -bottomConstant))
}
if let right = right {
anchors.append(rightAnchor.constraint(equalTo: right, constant: -rightConstant))
}
if widthConstant > 0 {
anchors.append(widthAnchor.constraint(equalToConstant: widthConstant))
}
if heightConstant > 0 {
anchors.append(heightAnchor.constraint(equalToConstant: heightConstant))
}
anchors.forEach({$0.isActive = true})
return anchors
}
}
The collection view automatically set to the whole view. The contents of the collectionView is able to adjust the insects automatically if you do not set any behavior. At this case set automatic adjustment false to get the full-screen view. The top and bottom of the screen have a safe area for adjusting view with the notch.
Try this
collectionView?.contentInsetAdjustmentBehavior = .never
Hope this will fix this issue.

Drop shadow on UITextView in Swift

I was searching this for a time but can't figure out how to implement the solutions I found.
Below post is defining what I really want and also It has a solution but in objective-c. I try to implement that solution but text started not to shown after that implementation.
UITextView bottom shadow on text
class AggrementView: UIView, UITextViewDelegate {
let acceptBtn = RippleButton()
let kvkkTextView = UITextView()
private let containerView = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
setupConstraints()
}
public convenience init(text: String, imageName: String){
self.init()
}
public convenience init(text: String, imageName: String, senderColor: UIColor){
self.init()
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI(){
self.backgroundColor = .clear
acceptBtn.translatesAutoresizingMaskIntoConstraints = false
//acceptBtn.backgroundColor = UIColor(red:0.40, green:0.69, blue:0.07, alpha:1.0)
acceptBtn.backgroundColor = UIColor.gray
acceptBtn.layer.cornerRadius = 6.0
acceptBtn.setTitle("Onaylıyorum", for: UIControlState.normal)
acceptBtn.titleLabel?.font = UIFont(name: "Corbert-Regular", size: 20)!
acceptBtn.setTitleColor(UIColor.flatWhite, for: UIControlState.normal)
//acceptBtn.setAllSideShadow(shadowShowSize: 8.0)
acceptBtn.accessibilityIdentifier = "acceptBtn"
acceptBtn.isEnabled = false
acceptBtn.setTitleColor(UIColor.lightGray, for: .disabled)
kvkkTextView.font = UIFont(name: "Corbert-Regular", size: 15)!
kvkkTextView.setContentOffset(CGPoint.zero, animated: false)
kvkkTextView.layer.cornerRadius = 6.0
kvkkTextView.backgroundColor = .clear
kvkkTextView.layer.borderColor = UIColor.flatGray.cgColor
kvkkTextView.textColor = UIColor.flatWhite
kvkkTextView.delegate = self
kvkkTextView.isEditable = false
containerView.backgroundColor = .clear
containerView.layer.cornerRadius = 6.0
self.addSubview(containerView)
containerView.addSubview(acceptBtn)
containerView.addSubview(kvkkTextView)
}
private func setupConstraints(){
containerView.anchor(self.topAnchor, left: self.leftAnchor, bottom: self.bottomAnchor, right: self.rightAnchor, topConstant: 90, leftConstant: 10, bottomConstant: 20, rightConstant: 10, widthConstant: 0, heightConstant: 0)
kvkkTextView.anchor(self.containerView.topAnchor, left: self.containerView.leftAnchor, bottom: self.acceptBtn.topAnchor, right: self.containerView.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 20, rightConstant: 0, widthConstant: 0, heightConstant: 0)
acceptBtn.anchor(nil, left: self.containerView.leftAnchor, bottom: self.containerView.bottomAnchor, right: self.containerView.rightAnchor, topConstant: 0, leftConstant: 10, bottomConstant: 10, rightConstant: 10, widthConstant: 0, heightConstant: 60)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
print( "View scrolled to the bottom" )
UIView.animate(withDuration: 0.5) {
self.acceptBtn.backgroundColor = UIColor(red:0.40, green:0.69, blue:0.07, alpha:1.0)
self.acceptBtn.isEnabled = true
}
}
let color = UIColor.lightGray
guard
let verticalIndicator = scrollView.subviews.last as? UIImageView,
verticalIndicator.backgroundColor != color,
verticalIndicator.image?.renderingMode != .alwaysTemplate
else { return }
verticalIndicator.layer.masksToBounds = true
verticalIndicator.layer.cornerRadius = verticalIndicator.frame.width / 2
verticalIndicator.backgroundColor = color
verticalIndicator.image = verticalIndicator.image?.withRenderingMode(.alwaysTemplate)
verticalIndicator.tintColor = .clear
}
Picture ref: #user2213271 in UITextView bottom shadow on text post
Here is the gradientCode I tried:
func applyShadow(){
var layerWidth: CGFloat = 8.0
var gl1 = CAGradientLayer()
var col1 = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0).cgColor
var col2 = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0).cgColor
gl1.colors = [col2, col1, col1, col2]
gl1.locations = [0.0, 0.0, 0.85, 1.0]
//underTextView - this is my UIView
gl1.frame = CGRect(x: 0, y: 0, width: underTextView.frame.width - layerWidth, height: underTextView.frame.height)
//layer for scrollIndicator - it must be visible always good
var gl2 = CAGradientLayer()
gl2.colors = [col1, col1]
gl2.locations = [0.0, 1.0]
gl2.frame = CGRect(x: underTextView.frame.width - layerWidth, y: 0, width: layerWidth, height: underTextView.frame.height)
//create main layer
var gl = CAGradientLayer()
gl.addSublayer(gl1)
gl.addSublayer(gl2)
//add to mask of UIView
underTextView.layer.mask = gl
}
It seems you forgot to add kvkkTextView.translatesAutoresizingMaskIntoConstraints = false before set kvkkTextView's anchor. So your kvkkTextView can't get its frame from constraints.

Close Button Not Working in Swift Playground

I am working on a Swift playground for WWDC. I need to have a UI Button that closes the web view and toolbars (the button is called closeButton and the function is at the bottom for the button), and returns to the previously screen when clicked (the first view). The code below is the Swift I have typed so far:
import UIKit
import WebKit
import PlaygroundSupport
import Foundation
PlaygroundPage.current.needsIndefiniteExecution = true
class MyViewController : UIViewController {
let cardView = UIView()
let accountButton = UIButton()
let coverImageView = UIImageView()
let swiftLogoView = UIImageView()
let openLabel = UILabel()
let titleLabel = UILabel()
let label = UILabel()
let captionLabel = UILabel()
let descriptionLabel = UILabel()
let backgroundImageView = UIImageView()
let closeButton = UIButton()
let openButton = UIButton()
let doneButton = UIButton()
let url1 = URL(string: "https://youtube.com/embed/uuxXHAKA1WY")!
let alertController = UIAlertController(title: "Who Made This Playground:", message: "Mark Bruckert made this playground for WWDC 2018. He is a Web and Graphic Designer learning Swift and IOS Design. He would love to attend this year, to learn the new frameworks revealed at the event and have IOS Engineers review his designs and code.", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "Close", style: .default, handler: nil)
let menuBar = UIView()
let doneLabel = UILabel()
let webView = UIWebView()
let cardView2 = UIView()
let coverImageView2 = UIImageView()
let titleLabel2 = UILabel()
let captionLabel2 = UILabel()
let descriptionLabel2 = UILabel()
let backgroundImageView2 = UIImageView()
let url2 = URL(string: "https://youtu.be/uuxXHAKA1WY")!
override func loadView() {
let view = UIView()
view.backgroundColor = .white
label.frame = CGRect(x: 20, y: 30, width: 272, height: 38)
label.text = "Dev Tutorials:"
label.textColor = .black
label.font = UIFont.systemFont(ofSize: 32, weight: .bold)
openLabel.frame = CGRect(x: 140, y: 215, width: 272, height: 38)
openLabel.text = "Play Video"
openLabel.textColor = .black
openLabel.font = UIFont.systemFont(ofSize: 32, weight: .semibold)
self.openLabel.alpha = 0
openLabel.layer.zPosition = 5
doneLabel.frame = CGRect(x: 25, y: 5, width: 272, height: 38)
doneLabel.text = "Done"
doneLabel.textColor = .white
doneLabel.font = UIFont.systemFont(ofSize: 32, weight: .light)
openLabel.layer.zPosition = 7
doneButton.addTarget(self, action: #selector(doneButtonTapped), for: .touchUpInside
)
cardView.frame = CGRect(x: 60, y: 100, width: 300, height: 250)
cardView.layer.cornerRadius = 14
cardView.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
cardView.layer.shadowOpacity = 0.25
cardView.layer.shadowOffset = CGSize(width: 0, height: 10)
cardView.layer.shadowRadius = 10
cardView2.frame = CGRect(x: 60, y: 100, width: 300, height: 250)
cardView2.layer.cornerRadius = 14
cardView2.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
cardView2.layer.shadowOpacity = 0.25
cardView2.layer.shadowOffset = CGSize(width: 0, height: 10)
cardView2.layer.shadowRadius = 10
titleLabel.frame = CGRect(x: 16, y: 16, width: 272, height: 38)
titleLabel.text = "Portals with ARKit"
titleLabel.textColor = .white
titleLabel.font = UIFont.systemFont(ofSize: 32, weight: .semibold)
captionLabel.frame = CGRect(x: 16, y: 204, width: 272, height: 40)
captionLabel.text = "by Jared Davidson"
captionLabel.textColor = .white
captionLabel.numberOfLines = 0
descriptionLabel.frame = CGRect(x: 20, y: 400, width: 335, height: 132)
descriptionLabel.text = "In this tutorial, you will learn how to use ARKit by Apple to transport yourself through a portal."
descriptionLabel.textColor = .black
descriptionLabel.numberOfLines = 10
descriptionLabel.alpha = 0
coverImageView.frame = CGRect(x: 0, y: 0, width: 300, height: 250)
coverImageView.contentMode = .scaleAspectFill
coverImageView.image = #imageLiteral(resourceName: "Cover.jpg")
coverImageView.clipsToBounds = true
swiftLogoView.frame = CGRect(x: 8, y: 8, width: 35, height: 35)
swiftLogoView.contentMode = .scaleAspectFill
swiftLogoView.image = #imageLiteral(resourceName: "Swift_logo.png")
swiftLogoView.clipsToBounds = true
coverImageView.layer.cornerRadius = 14
accountButton.frame = CGRect(x: 360, y: 20, width: 55, height: 55)
accountButton.backgroundColor = #colorLiteral(red: 0.803921580314636, green: 0.803921580314636, blue: 0.803921580314636, alpha: 1.0)
accountButton.layer.cornerRadius = 30
accountButton.addTarget(self, action: #selector(accountButtonTapped), for: .touchUpInside)
closeButton.frame = CGRect(x: 360, y: 20, width: 28, height: 28)
closeButton.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.5)
closeButton.layer.cornerRadius = 14
closeButton.setImage(#imageLiteral(resourceName: "Action-Close#2x.png"), for: .normal)
closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside)
closeButton.alpha = 0
openButton.frame = CGRect(x: 100, y: 200, width: 220, height: 75)
openButton.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
openButton.layer.cornerRadius = 14
openButton.addTarget(self, action: #selector(openButtonTapped), for: .touchUpInside)
openButton.alpha = 0
doneButton.frame = CGRect(x: 10, y: 5, width: 130, height: 50)
doneButton.layer.borderWidth = 3.0
doneButton.layer.borderColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
doneButton.layer.cornerRadius = 14
doneButton.addTarget(self, action: #selector(doneButtonTapped), for: .touchUpInside)
cardView.addSubview(coverImageView)
cardView.addSubview(openLabel)
doneButton.addSubview(doneLabel)
cardView.addSubview(closeButton)
cardView.addSubview(openButton)
menuBar.addSubview(doneButton)
cardView.addSubview(descriptionLabel)
view.addSubview(cardView)
view.addSubview(label)
view.addSubview(accountButton)
let tap = UITapGestureRecognizer(target: self, action: #selector(cardViewTapped))
cardView.addGestureRecognizer(tap)
cardView.isUserInteractionEnabled = true
doneButton.isUserInteractionEnabled = true
self.view = view
}
#objc func cardViewTapped() {
let animator = UIViewPropertyAnimator(duration: 0.7, dampingRatio: 0.7) {
self.cardView.frame = CGRect(x: 0, y: 0, width: 450, height: 667)
self.label.layer.isHidden = true
self.cardView.layer.cornerRadius = 0
self.titleLabel.frame = CGRect(x: 20, y: 20, width: 374, height: 38)
self.captionLabel.frame = CGRect(x: 20, y: 370, width: 272, height: 40)
self.descriptionLabel.alpha = 1
self.coverImageView.frame = CGRect(x: 0, y: 0, width: 450, height: 420)
self.coverImageView.layer.cornerRadius = 0
self.closeButton.alpha = 1
self.openButton.alpha = 0.7
self.accountButton.alpha = 0
self.openLabel.alpha = 1
}
animator.startAnimation()
}
#objc func closeButtonTapped() {
let animator = UIViewPropertyAnimator(duration: 0.7, dampingRatio: 0.7) {
self.cardView.frame = CGRect(x: 60, y: 100, width: 300, height: 250)
self.cardView.layer.cornerRadius = 14
self.titleLabel.frame = CGRect(x: 16, y: 16, width: 272, height: 38)
self.captionLabel.frame = CGRect(x: 16, y: 204, width: 272, height: 40)
self.descriptionLabel.alpha = 0
self.coverImageView.frame = CGRect(x: 0, y: 0, width: 300, height: 250)
self.coverImageView.layer.cornerRadius = 14
self.closeButton.alpha = 0
self.label.layer.isHidden = false
self.openButton.alpha = 0
self.openLabel.alpha = 0
self.accountButton.alpha = 1
}
animator.startAnimation()
}
#objc func openButtonTapped() {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 600))
view.backgroundColor = UIColor.lightGray
PlaygroundPage.current.liveView = view
menuBar.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(menuBar)
menuBar.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
menuBar.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
menuBar.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
menuBar.heightAnchor.constraint(equalToConstant: 64.0).isActive = true
menuBar.backgroundColor = #colorLiteral(red: 0.803921580314636, green: 0.803921580314636, blue: 0.803921580314636, alpha: 1.0)
let toolbar = UIView()
toolbar.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(toolbar)
toolbar.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
toolbar.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
toolbar.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
toolbar.heightAnchor.constraint(equalToConstant: 64.0).isActive = true
toolbar.backgroundColor = #colorLiteral(red: 0.803921580314636, green: 0.803921580314636, blue: 0.803921580314636, alpha: 1.0)
webView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(webView)
webView.topAnchor.constraint(equalTo: menuBar.bottomAnchor, constant: 8.0).isActive = true
webView.bottomAnchor.constraint(equalTo: toolbar.topAnchor, constant: -8.0).isActive = true
webView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
webView.loadRequest(URLRequest(url: URL(string:"https://youtube.com/embed/uuxXHAKA1WY")!))
}
#objc func accountButtonTapped() {
present(alertController, animated: true, completion: nil)
alertController.addAction(defaultAction)
}
#objc func doneButtonTapped() {
self.webView.alpha = 0
self.view.alpha = 0
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
Thanks in advance for your help,
Mark B.
In method openButtonTapped, Local variable view created problem to your code. Also, you called liveView again. I have modified your code, it is working assumed that last screen will go to previous.
First, declare the toolBar as member variable like menuBar.And you the following code. Tap done button will go to previous.
#objc func openButtonTapped() {
view.backgroundColor = UIColor.cyan
menuBar.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(menuBar)
menuBar.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
menuBar.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
menuBar.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
menuBar.heightAnchor.constraint(equalToConstant: 64.0).isActive = true
menuBar.backgroundColor = #colorLiteral(red: 0.803921580314636, green: 0.803921580314636, blue: 0.803921580314636, alpha: 1.0)
toolbar.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(toolbar)
toolbar.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
toolbar.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
toolbar.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
toolbar.heightAnchor.constraint(equalToConstant: 64.0).isActive = true
toolbar.backgroundColor = #colorLiteral(red: 0.803921580314636, green: 0.803921580314636, blue: 0.803921580314636, alpha: 1.0)
webView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(webView)
webView.topAnchor.constraint(equalTo: menuBar.bottomAnchor, constant: 8.0).isActive = true
webView.bottomAnchor.constraint(equalTo: toolbar.topAnchor, constant: -8.0).isActive = true
webView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
webView.loadRequest(URLRequest(url: URL(string:"https://youtube.com/embed/uuxXHAKA1WY")!))
}
#objc func accountButtonTapped() {
present(alertController, animated: true, completion: nil)
alertController.addAction(defaultAction)
}
#objc func doneButtonTapped() {
print("test")
self.webView.stopLoading()
self.webView.alpha = 0
toolbar.removeFromSuperview()
menuBar.removeFromSuperview()
}

Resources