So I’m coding my first app, yeah, from scratch and I never done anything like it before so please bear with me.
I wanna take the randomised value of the first constant and use it to determine the content shown on screen through a label upon a view controller, this might be quite easy for some people but I am really struggling here. I commented out my code so you know what i intend it to do. Now, I know I could approach this many different ways such as not having a label at all and photoshop phrases on images but nah…. I wanna CODE!
Any ideas? Thank you all very much :3 <3
import UIKit
class ViewController: UIViewController {
let random = Int(arc4random_uniform(11)) //Randomised int values from 0 to 11 (-1)
@IBOutlet weak var text: UILabel!
@IBOutlet weak var phrase: UIButton! //this button should reset the entire process over again
@IBOutlet var imageauthor: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self .imageauthor.image = UIImage(named:"0(random).jpg") //Viewcontroller displays a random image out of randomised value
self .text.text = ("''") //this should somehow check what the randomised value is and call the Uilabel text bellow it
}
var string1 = ("My fist app has many holes1")
... string2 = ("My fist app has many holes2")
... string3....
2
Answers
sentences
).0
andsentences.count
(not included).sentences
array.Like this:
Concretely it should be something like this :
//1 Create a connection
Action
on your button : It’s the same process asOutlet
but selectConnection : Action
andType : UIButton
instead. And execute your random function on click. See documentation//2 Declare a array with all your sentences inside. Respect the order.
//3 Execute your random function on viewDidLoad
//4 Create the function
showRandom()
who put the random image and the according text into your imageView and label.