The picture goes up because the description is long how can I fix this? - swift

When the picture description is long, my picture disappears, I can't see it. How can I show full size of text and full size of images?
How can I scroll the text up and down?
FavoriteDetailViewController
import UIKit
import ProgressHUD
class FavoriteDetailViewController: UIViewController {
#IBOutlet weak var shortdescriptionLabel: UILabel!
#IBOutlet weak var favoriteImageView: UIImageView!
#IBOutlet weak var favoriteTitleLabel: UILabel!
#IBOutlet weak var descriptionLabel: UILabel!
#IBOutlet weak var nameField: UITextField!
var breed: Breed!
override func viewDidLoad() {
super.viewDidLoad()
populateView()
}
private func populateView() {
favoriteImageView.kf.setImage(with: breed.image?.asUrl)
favoriteTitleLabel.text = breed.name
descriptionLabel.text = breed.description
shortdescriptionLabel.text = breed.shortDescription
}
#IBAction func favoriteButton(_ sender: UIButton) {
guard let name = nameField.text?.trimmingCharacters(in: .whitespaces),
!name.isEmpty else {
ProgressHUD.showError("Please enter your name")
return
}
print("Hello \(name)")
}
}
I made the text smaller but it's very illegible
I dropped the spacing, it looks bad too
I want to make the whole text look nice and not spoil the picture. What is the solution? Is it possible to move the label up and down?

Related

How to resize the detailsView after cross button is clicked after the closing view is hidden?

[![when the cross button is clicked, the closingView is hidden.][1]][1]
import UIKit
import IBAnimatable
class ViewController: UIViewController {
#IBOutlet weak var closingView: AnimatableView!
#IBOutlet weak var detailsView: AnimatableView!
#IBOutlet weak var btnClose: UIButton!
#IBOutlet weak var closeViewBtn: UIView!
#IBOutlet weak var scrollView: UIScrollView!
var isCloseButtonTapped = false
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func btnCloseAction(_ sender: Any) {
isCloseButtonTapped = !isCloseButtonTapped
if isCloseButtonTapped{
closingView.isHidden = true
}else{
//
}
}
}
[1]: https://i.stack.imgur.com/CpH2A.png
You can add closingView and detailsView inside a UIStackView. When the closingView is hidden the detailsView will fill up the entire space in the parent UIStackView.

How can I carry out multiple different animations at different times with the same UIButton?

I am creating an animation sequence where when one button is pressed one object fades out. When the same button is pressed again another object fades out. This keeps happening until 8 objects are faded out. I have tried and played around with code and so far have got the code to fade out one object, and two or more at a time, but have not successfully been able to do it as described above. This is my code so far:
import UIKit
class DrinkWaterViewController: UIViewController {
#IBOutlet weak var glassOne: UIImageView!
#IBOutlet weak var glassTwo: UIImageView!
#IBOutlet weak var glassThree: UIImageView!
#IBOutlet weak var glassFour: UIImageView!
#IBOutlet weak var glassFive: UIImageView!
#IBOutlet weak var glassSix: UIImageView!
#IBOutlet weak var glassSeven: UIImageView!
#IBOutlet weak var glassEight: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.glassOne.alpha = 1.0
self.glassTwo.alpha = 1.0
}
#IBAction func drunkOne(_ sender: Any){
if self.glassOne.alpha == 1.0{
UIView.animate(withDuration: 1.5, delay: 0.2, animations:
{self.glassOne.alpha = CGFloat(0.1)}
)
}
}
Put your glasses into an array glasses and add a property to keep track of nextToFade. Then just fade the glasses[nextToFade] and increment nextToFade by 1:
class DrinkWaterViewController: UIViewController {
#IBOutlet weak var glassOne: UIImageView!
#IBOutlet weak var glassTwo: UIImageView!
#IBOutlet weak var glassThree: UIImageView!
#IBOutlet weak var glassFour: UIImageView!
#IBOutlet weak var glassFive: UIImageView!
#IBOutlet weak var glassSix: UIImageView!
#IBOutlet weak var glassSeven: UIImageView!
#IBOutlet weak var glassEight: UIImageView!
// array to hold the glasses so that they can be indexed
var glasses = [UIImageView]()
// index of next glass to fade
var nextToFade = 0
override func viewDidLoad() {
super.viewDidLoad()
// put the glasses into the array
glasses = [glassOne, glassTwo, glassThree, glassFour,
glassFive, glassSix, glassSeven, glassEight]
// make sure they're all visible
glasses.forEach { $0.alpha = 1.0 }
}
#IBAction func drunkOne(_ sender: Any) {
// make sure not to index beyond the end of the array
guard nextToFade < glasses.count else { return }
let glass = glasses[nextToFade]
nextToFade += 1
UIView.animate(withDuration: 1.5, delay: 0.2, animations:
{ glass.alpha = 0.1 }
)
}
}

Can't make sens of UIStepper (S)

I'm trying to make an app to count different tokens in a board game. I thought it would be easy peasy, but not quite.
I succeeded in adding one UIStepper to count one kind of token, but I don't know how to add the other four. This is what I've got so far:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var theLabel: UILabel!
#IBOutlet weak var stepper: UIStepper!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
#IBAction func StepperTapped(sender: UIStepper) {
self.theLabel.text = "\(self.stepper.value)"
}
}
I got one action and two outlets.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var theLabel: UILabel!
#IBOutlet weak var stepper: UIStepper!
#IBOutlet weak var theLabel2: UILabel!
#IBOutlet weak var stepper2: UIStepper!
#IBOutlet weak var theLabel3: UILabel!
#IBOutlet weak var stepper3: UIStepper!
#IBOutlet weak var theLabel4: UILabel!
#IBOutlet weak var stepper4: UIStepper!
#IBOutlet weak var theLabel5: UILabel!
#IBOutlet weak var stepper5: UIStepper!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
#IBAction func StepperTapped(sender: UIStepper) {
self.theLabel.text = "\(self.stepper.value)"
}
#IBAction func StepperTapped2(sender: UIStepper) {
self.theLabel2.text = "\(self.stepper2.value)"
}
#IBAction func StepperTapped3(sender: UIStepper) {
self.theLabel3.text = "\(self.stepper3.value)"
}
#IBAction func StepperTapped4(sender: UIStepper) {
self.theLabel4.text = "\(self.stepper4.value)"
}
#IBAction func StepperTapped5(sender: UIStepper) {
self.theLabel5.text = "\(self.stepper5.value)"
}
}

SWIFT: UIImageView Photo Going Past Boundaries

Can anybody tell me why my photos go beyond the boundary of UIImageView?
The pictures end up covering the buttons below it.
My code:
import UIKit
class ViewController: UIViewController {
#IBOutlet var Photo: UIImageView!
#IBOutlet var QuestionLabel: UILabel!
#IBOutlet var Button1: UIButton!
#IBOutlet var Button2: UIButton!
#IBOutlet var Button3: UIButton!
#IBOutlet var Button4: UIButton!
#IBOutlet var LabelEnd: UILabel!
var CorrectAnswer = String()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Hide()
Photo.layer.cornerRadius = self.Photo.frame.size.width / 10
Photo.clipsToBounds = true
Photo.layer.masksToBounds = true
Photo.layer.borderWidth = 1
Photo.layer.borderColor = UIColor.blackColor().CGColor
Photo.contentMode = .ScaleAspectFit
Photo.contentMode = .ScaleAspectFill
RandomQuestions()
}
I apologize for being such a novice, just learning how to code.
Are you sure it's going beyond the boundary of your image view?
Try printing out the frame of your view to double check. Doesn't look like you have constraints set up from that screenshot - maybe your image view is sized to fit.

Update labels from unwind segue

I'm trying to change the labels of a viewController after a certain action is taken from a modal view which triggers an unwind segue.
Once unwind segue happens the labels of the current view (the one which the modal was covering) should be changed.
My current attempt at doing this is resulting in a "unexpectedly found nil while unwrapping an Optional value" error. Here is the code:
class DataViewController: UIViewController {
var experiment: NSDictionary?
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var bodyLabel: UILabel!
#IBOutlet weak var tlRightLine: UIImageView!
#IBOutlet weak var tlLeftLine: UIImageView!
#IBOutlet weak var brRightLine: UIImageView!
#IBOutlet weak var brLeftLine: UIImageView!
#IBOutlet weak var bodyTest: UITextView!
#IBAction func removeExperimentSegue(unwindSegue:UIStoryboardSegue) {
removeExperiment = true
titleLabel.text = "Done"
bodyLabel.text = "Done"
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if let dict: NSDictionary = experiment {
if let title = dict.objectForKey("title") as? String {
self.titleLabel!.text = title
}
if let body = dict.objectForKey("body") as? String {
self.bodyTest!.text = body
}
} else {
self.titleLabel!.text = ""
self.bodyLabel!.text = ""
}
}
}
What am I doing wrong?
I did! I ended up using a global boolean variable. I set it true on the initial load of the menu and then had it flip to false during the unwind segue.
var removeExperiment = false
class DataViewController: UIViewController {
#IBAction func removeExperimentSegue(unwindSegue:UIStoryboardSegue) {
removeExperiment = true
}
if removeExperiment == true {
doneLabel.text = "You've completed this experiment. You won't see it again unless you hit 'Reset' from the Home menu."
}
}
Hope that helps!