Countdown to 0 on button tap [closed] - ios

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to add a feature like in the TAMAGO application. When you click on a button, the label will change numbers. If it starts on 100, you tap the egg and "100" changes to "99", tap it again and it will change to "98".
My code is:
`-(IBAction)buttonpress:(id)sender {
if (button.highlighted) {
YES;
label.text = #"999";
if (button.highlighted) {
NO;
label.text = #"998";
}
}`
I tried to repeat this process. But it doesn't work.

This is what you want:
- (IBAction)buttonPress:(UIButton *)sender {
self.myTextLabel.text = [NSString stringWithFormat:#"%d", [self.myTextLabel.text intValue]-1]
}
In this case though the button must have a numeric value when pressed. You could put some further checks in to make sure it is a number if you want. Let me know if you need any further help.

Related

Display array in question label and button label [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have an array of questions and 3 answers and i want to display the question in the text label and the three answers in each button label. The text label and each button have an outlet. Im a begginer at swift and im having trouble extracting from the array
struct Questions {
let allQuestions = [
"The easiest way to learn is:",
"When buying clothes i usually make the decision on the basis of:"
]
let answers = [
[
"By viewing, reading, and observing how the others carry out certain tasks",
"By listening, discussing and doing according to verbal instructions",
"By doing and experimenting by myself",
],
[
"By their appearance and looks",
"Their practicality and use",
"How comfortable they are or how they feel"
]
]
// Initialise your struct
var questions = Questions()
//Keep track of what question you're on. Update this when you reload view
var questionNumber: Int = 0
//Add buttons to outlet collection
#IBOutlet var answerButtons: [UIButton]!
//Populating a question is simple
let aQuestion = questions.allQuestions[questionNumber]
yourQuestionLabel.text = "\(aQuestion)"
//For answers, loop through buttons outlet collection
for x in 0..<questions.answers[questionNumber].count {
answerButton[x].titleLabel?.text = "\(questions.answers[questionNumber][x])"
}

Swift textfield text 1 to 9 if user entered need to show alert [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying simple logic, I have only one textfield. into this textfield if user entered 1 to 9 I need to show alert using if.
if emailTextField.text < 0 {
print("100%")
}
UITextField's text is always a String. So if you need to check if it is a particular number, you need to cast the String value to an Int.
if let number = Int(emailTextField.text!), (0...9).contains(number) {
print("100%)
}
Note: You might want to check out the UITextFieldDelegate methods if your logic revolves around text field editing events.
yourTextField.addTarget(self, action: #selector(valueChanged(_:)), for: .valueChanged)
.
.
.
#objc func valueChanged(_ textField: UITextField) {
if let number = Int(emailTextField.text!), (0...9).contains(number) {
print("100%)
}
}
Sidenote: I have no idea what your use case is for this.

How to implement the function to swipe to next page in flutter? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm now working on implementing the function to swipe to the next page for people to browse. Yeah, it's just like the swipe function of Tinder. I have searched the Internet but only found swipe to delete. Can anyone give me a hint?
What you want is PageView
It's a widget that includes all the logic for page swipe gestures.
You may use GestureDetector. it has almost all drags available. Here is an example:
GestureDetector(
onHorizontalDragEnd: (DragEndDetails details) => _onHorizontalDrag(details),
child: Container()
)
and the function:
void _onHorizontalDrag(DragEndDetails details) {
if(details.primaryVelocity == 0) return; // user have just tapped on screen (no dragging)
if (details.primaryVelocity.compareTo(0) == -1)
print('dragged from left');
else
print('dragged from right');
}
You can do something like this..
GestureDetector (
onPanUpdate: (dis) {
if (dis.delta.dx > 0) {
//User swiped from left to right
} else if (dis.delta.dx < 0) {
//User swiped from right to left
}
}
child: yourWidget,
)
Hope it answers your question..

NSNotification for UIAlertController [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there an option to observe and get the information about appearing and disappearing?
I want to grayscale my elements like apple ui-elements by appearing of UIAlertController!
Since now i found out that the "_UIBackdropViewComputeAndApplySettingsNotification" was called and contains userInfo about the appearing view.
You are going to make the UIAlertController's view appear, so how can you not know? You don't need to observe it; you're doing it (by calling presentViewController...).
That takes of what happens when the alert appears. What about when it disappears? Well, it disappears because the user tapped a button. You get to write the handler for every button in the alert. So again, you know when the alert is disappearing, because your handler is running.
The solution is, everything works automatically. You just have to implement..
override func tintColorDidChange() {
self.setNeedsDisplay()
}
..and of course working with the tintColor
Thanks matt for quick answer!
To expand on the other answers: each of your UIView subclasses should implement tintColorDidChange to be notified of the change.
Here's a sample implementation:
class someLabel : UILabel {
override func tintColorDidChange() {
let isInactive = self.tintAdjustmentMode == UIViewTintAdjustmentMode.Dimmed
if (isInactive) {
// modify subviews to look disabled
self.textColor = UIColor.grayColor()
} else {
// modify subviews to look enabled
self.textColor = self.tintColor
}
}
}
A few other good code samples (albeit in Objective-C) can be found in this SO question.

width of the button [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
who we change the width of the button. i am use 2 buttons. i want display on all width of the screen.
class Main extends UiApplication {
public Main(){
pushScreen(new TestScreen());
}
public static void main(String args[])
{
Main app = new Main();
app.enterEventDispatcher();
}
}
class TestScreen extends MainScreen {
public TestScreen() {
ButtonField bt = new ButtonField("all width"){
public int getPreferredWidth() {
return net.rim.device.api.system.Display.getWidth();
}
};
this.add(bt);
}
}

Resources