I use a func textFieldShouldReturn that depending on what Integer I have in the textField it will either display an x or a check. I have 3 textFields but the func only works for numAnswerOne. How do I make it work for all 3 textFields?
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
//makes a return key work
textField.resignFirstResponder()
let text = textField.text
let numAnswerOne = Int(answerOne.text!)
let numAnswerTwo = Int(answerTwo.text!)
let numAnswerThree = Double(answerThree.text!)
if numAnswerOne == 70 {
checkOne.alpha = 1
wrongOne.alpha = 0
answerOne.isUserInteractionEnabled = false
} else if numAnswerOne != 70 {
wrongOne.alpha = 1 //function stops here
} else if numAnswerTwo == 2 {
checkTwo.alpha = 1
wrongTwo.alpha = 0
answerTwo.isUserInteractionEnabled = false
} else if numAnswerTwo != 2 {
wrongTwo.alpha = 1
} else if numAnswerThree == 30.1 {
checkThree.alpha = 1
checkThree.alpha = 0
checkThree.isUserInteractionEnabled = false
} else if numAnswerThree != 30.1 {
checkThree.alpha = 0
}
return true
}
Post
Replies
Boosts
Views
Activity
I want my textfield after I click done on the keyboard to move the slider. I'm not really sure how to do that though. Is there a way to do it or do I need a button?
I don't understand why my animations seem to override my user interaction when I try to tap on a label. What am I missing?
let tapGestureR = UITapGestureRecognizer(target: self, action: #selector(self.tapRev))
revLabel.addGestureRecognizer(tapGestureR)
let tapGestureP = UITapGestureRecognizer(target: self, action: #selector(self.tapPro))
proLabel.addGestureRecognizer(tapGestureP)
I'm trying to get my animations to work on my labels I have programmatically but when I add them it seems to override my .isuserinteractionenabled. How do I enable these animations?
override func viewDidLoad() {
super.viewDidLoad()
proLabel.frame = CGRect(x: 120, y: 840, width: 45, height: 16)
proLabel.text = "profit"
proLabel.textColor = UIColor.black
proLabel.backgroundColor = UIColor.systemBlue
proLabel.font = UIFont(name: "System", size: 15)
proLabel.isUserInteractionEnabled = true
self.content.addSubview(proLabel)
revLabel.frame = CGRect(x: 20, y: 840, width: 65, height: 16)
revLabel.text = "revenue"
revLabel.textColor = UIColor.black
revLabel.backgroundColor = UIColor.systemRed
revLabel.font = UIFont(name: "System", size: 15)
revLabel.isUserInteractionEnabled = true
self.content.addSubview(revLabel)
let tapGestureR = UITapGestureRecognizer(target: self, action: #selector(self.tapRev))
revLabel.addGestureRecognizer(tapGestureR)
let tapGestureP = UITapGestureRecognizer(target: self, action: #selector(self.tapPro))
proLabel.addGestureRecognizer(tapGestureP)
animatePro() //animation added
animateRev() //animation added
buttonNext.layer.cornerRadius = 10
}
I am trying to have 2 animations one that increases the label's size and makes it return to its original form but I can't repeat the shrinking like I can increasing the size. How can I shrink it it on loop?
func animateLabels() {
UIView.animate(withDuration: 2, delay: 0, options: .repeat, animations: {
//1.5 times it's normal size
self.proLabel.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}){ (finished) in
UIView.animate(withDuration: 2, delay: 2, options: .repeat, animations: {
self.proLabel
.transform = CGAffineTransform.identity
})
}
}
Is there such a thing as starting point modifiers when you want a UIView to go back to where it originally was before you did any action to it.
I'm trying to have my label theView intersect another label called tot.
if theView.frame.intersects(tot.frame.?.?)
but I want the intersection to be the left side of the tot. How can I go about doing that?
I'm building a project that uses SwiftUi, Swift Ui template, CoreData and CloudKit and I automatically get the error "cannot find the item in scope" located in my content view twice. Why does that happen when I select CloudKit before building the project?
I'm having trouble making my iPhone app in the storyboard look the same on wider iPhones when I run it. I use a freeform style that is 375 by 1000.
Im getting the error "An internal error occurred. Editing functionality may be limited." When I look at storyboard I see blue backgrounds on my labels. What does this mean? How can I fix it?
I use Xcode a lot and recently when I click on something in the storyboard like a label it will pause for some time (little over a minute). my iMac uses 8gb of ram and on activity monitor it shows its using around 6.5gb of ram how can I improve the performance of Xcode so it does not do that?
In my parent I have a function that uses 4 sliders from each child class, and it calculates return on assets. How do I move this method to the child classes so it can update when a slider moves?
func calROA() {
let ans = Double(revNum - costNum)/Double(fixANum + curANum)
let perAns = ans * 100
print("this is the value for revenue " + "\(revNum)")
print("this is the value for costs " + "\(costNum)")
print("this is the value for fixed assets " + "\(fixANum)")
print("this is the value for current assets " + "\(curANum)")
print("this is the roa " + "\(perAns)")
roaLabel.text = String(format: "%.1f%%", perAns)
}
I have StackViews enclosed in a view and whenever I scroll upwards the view collapses, its height shrinks basically. I want the view to not move when I scroll upwards. How do I do that?
I'm trying to display different information from an api but all the values are nil. How do I unwrap them?func update(with item: CurrentPlayer) { firstName?.text = item.firstName lastName?.text = item.lastName team?.text = item.team position?.text = item.positionCategory playImg?.image = UIImage(named: "Grey") imageController.fetchItemArtwork(url: item.photoUrl) { (image) in if let image = image { DispatchQueue.main.async { self.playImg?.image = image } } } }
I keep getting the error "Timed out waiting for the simulator application for iphonesimulator to become ready". How do I fix it?