Display PercentDone UIProgressView in UiLabel - uilabel

I have a button connected to a UiProgressView, has only the function to count the clicks on the button ... I need to show the percentage of completion in a UILabel .. Can you tell me which method is better?
To make you understand the function I show you the code of the IBAction
- (IBAction)FFAddCFU:(id)sender {
if (FFVariabileNumerica_CFU >= 30)
return;
FFVariabileNumerica_CFU++ ;
[FFCFULabel setText:[NSString stringWithFormat:#"%d", FFVariabileNumerica_CFU]];
if(FFProgressBar.progress == 0.50 || FFProgressBar.progress == 0.77 ){
[ FFProgressBar setProgress : FFProgressBar.progress +0.25 ];
} else {
if (FFProgressBar.progress > 0.76) {
[ FFProgressBar setProgress : FFProgressBar.progress +0.25 ]; }
}
}

I've done this in a small project of mine for a custom progress view. It can be found at lightdesign/LDProgressView. You can take a look at the file LDProgressView.m for how I've done this.
Here's the relevant line:
label.text = [NSString stringWithFormat:#"%.0f%%", self.progress*100];
This line takes the progress value which is between 0.0 and 1.0 and multiplies it by 100 and then inserts the number up to the whole number (.0 in the format string) with a percentage at the end (%% in the format string).
Also, if you don't want to manually calculate the percentage, feel free to use the open source control I've made.

Related

How to get multiple sprites to bounce off the bounds of a scene in Objective-C

I have a game I'm creating with sprite-kit with 25 sprites that are all children of one sprite node BOMNeutNode. At the beginning of the game I create 25 child nodes within the scene using a for-loop, and set them all moving in a random direction using physicsBody.velocity.
What I want to do is to get them to bounce off the bounds of the scene when they reach the edge. I assumed the code below would do the trick to begin with, but it only seems to work on 1 of the 25 nodes (for that one node it is working perfectly well). I'm thinking this must be due to where I have this code positioned in my GamePlayScene code. I thought it would be appropriate to put it in the update section of the game run loop. Maybe I have to set this rule in the node itself?
I also thought it might be that I need to identify ALL nodes named #"Neut" but I can't find the syntax to do this. Please let me know if you need more code than I have provided.
(void) update:(NSTimeInterval)currentTime {
BOMNeutNode *neut = (BOMNeutNode*)[self childNodeWithName:#"Neut"];
if (neut.position.y > self.frame.size.height-50) {
neut.physicsBody.velocity = CGVectorMake(0, -100);
} else if (neut.position.y < 50) {
neut.physicsBody.velocity = CGVectorMake(0, 100);
} else if (neut.position.x > self.frame.size.height-50) {
neut.physicsBody.velocity = CGVectorMake(-100, 0);
} else if (neut.position.x < 50) {
neut.physicsBody.velocity = CGVectorMake(100, 0);
}
}
Any suggestions would be greatly appreciated.
One easy way to do this is to add a SKPhysicsBody created with bodyWithEdgeLoopFromRect: to your SKScene. That way the physics engine can handle all the bouncing for you (with the correct angles and everything).
Typically you'd want to add it in your SKScene's didMoveToView: method. Something like:
- (void)didMoveToView:(SKView*)view {
// ... any other setup you might need ...
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(50, 50, self.size.width - 100, self.size.hight - 100)];
}
If you go this route, that should take care of everything; you shouldn't need the code you currently have in your update: method.
The problem is that you have many nodes called Neut and its finding one of them and checking if its inside the frame, what you need to do is to find all nodes with that name and run the code on all of them
-(void)update:(NSTimeInterval)currentTime {
[self enumerateChildNodesWithName:#"Neut" usingBlock:^(SKNode *node, BOOL *stop) {
if (node.position.y > self.frame.size.height-50) {
node.physicsBody.velocity = CGVectorMake(0, -100);
} else if (node.position.y < 50) {
node.physicsBody.velocity = CGVectorMake(0, 100);
} else if (node.position.x > self.frame.size.height-50) {
node.physicsBody.velocity = CGVectorMake(-100, 0);
} else if (node.position.x < 50) {
node.physicsBody.velocity = CGVectorMake(100, 0);
}
}];
}

How to calculate the swap (rollover) in mt5 in term of account currency

Backgound:
using mt5
"swap" (rollover) price is defined in points (0.00001/0.001) - 5-digit broker
account currency: USD
The question is: how to calculate the "swap value" in terms of acc. currency in mt5. With other words, how many cents i will paid for one day rollover?
Currently have this "mql5" script:
#include <Trade\SymbolInfo.mqh>
void OnStart() {
CSymbolInfo sym; // symbol informations object
sym.Name( ChartSymbol() ); // get the object for the current chart symbol
if( sym.SwapMode() == SYMBOL_SWAP_MODE_POINTS) {
double lot = 0.1;
double swapUSD_long = sym.SwapLong() * 0; // need help here
double swapUSD_short = sym.SwapShort() * 0; // need help here
PrintFormat(
"symbol: %s swap_long: %.2f swap_short: %.2f swapUSD_long: %.2f swapUSD_short: %.2f",
sym.Name(),
sym.SwapLong(),
sym.SwapShort(),
swapUSD_long,
swapUSD_short
);
}
}
When attaching the script to EURAUD, it prints to terminal:
symbol: EURAUD swap_long: -10.80 swap_short: 6.80 swapUSD_long: 0.00
swapUSD_short: 0.00
so: the rollover price is 6.8 points for the short position. How to convert it to USD with current rate? For this need:
find the pair with the acc currency (in this case need find AUDUSD)
get the rate of AUDUSD sym.Bid() or sym.Ask()
and ...
simply need some help ;)
If I understand right your question, you can use the TickValueProfit and TickValueLoss. If the swap to some direction is negative (you will pay) use the TickvalueLoss and when positive use TickValueProfit.
You can make a function for this like the next:
double swap_value_currency(double value_point, double tickprofit, double tickloss)
{
if( value_point == 0.0 ) { return(0.0); }
if( value_point < 0.0 ) {
return( val * tickloss );
}
return( value_point * tickprofit);
}
The swap_value_currency returns the swap value depending on winning or losing for one standard lot.
so your fragment of code can be:
if( sym.SwapMode() == SYMBOL_SWAP_MODE_POINTS)
{
double swval_long = swap_value_currency(sym.SwapLong(), sym.TickValueProfit(), sym.TickValueLoss());
double swval_short= swap_vallue_currency(sym.SwapShort(), sym.TickValueProfit(), sym.TickValueLoss() );
}
and because this is for one standard lot, you need multiply it with your lot size...

UiProgressView Increment Value Action

I would have to use a necessiva progressView for the management of a small form. In a nutshell I have several actions that the user must carry through a click of UIButton and these actions should increase the progressview until completion . Let me give an example :
Let's start with a progressView set to 0.3
Button 1 is clicked and doing the action increases the progressview of 0.1 , so the progress is updated up to 0.4
The button 2 is clicked and increased by another 0.1 , and then the progressview becomes 0.5.
That's what I should do ... Currently I am stuck because if I make these actions I find myself 0.3 ( starting ) to 0.1 instead of me that serves 0.1 increments to any button is pushed ..
How can I solve the problem ... ? ? I'll post a little ' code
- (Void) viewDidLoad
{
    [super viewDidLoad ] ;
    FFProgressBar.progress = 0.3 ;
}
- ( IBAction ) FFAddVotazione : (id ) sender {
if ( FFVariabileNumerica_CFU_Votazione > = 30 )
return;
FFVariabileNumerica_CFU_Votazione + + ;
[ FFVotazioneLabel setText : [ NSString stringWithFormat : # " % d", FFVariabileNumerica_CFU_Votazione ]] ;
    [ FFProgressBar setProgress : +0.1 ] ;
}
- (IBAction)FFAddCFU:(id)sender {
if (FFVariabileNumerica_CFU_Votazione >= 30)
return;
FFVariabileNumerica_CFU_Votazione++ ;
[FFCFULabel setText:[NSString stringWithFormat:#"%d", FFVariabileNumerica_CFU_Votazione]];
[FFProgressBar setProgress:+0.1];
}

Using NSStepper to set ceiling value instead of incrementing value

I am using a NSStepper along with a NSTextField. The user can either set the value using the text field or can use the NSStepper to change the value. I will quote my question using the example below:
Suppose the current value of my stepper is 4 and increment value of the stepper is 2:
After I click the UP arrow on the NSStepper the value becomes:
Now Suppose the current value would have been 4.5 i.e.:
After using the UP arrow the value becomes:
What I require is that when the current value is 4.5, after using the UP arrow, the value becomes 6 instead of 6.5
Any ideas to accomplish this are highly appreciated!
What I require is that when the current value is 4.5, after using the
UP arrow, the value becomes 6 instead of 6.5
Hard to tell exactly what you are asking but taking a guess: it sounds like you want to remove the decimal part of the number and increment by your defined step amount (2). You can do this through the floor() function. See here for other Objective-C math functions
double floor ( double ) - removes the decimal part of the argument
NSLog(#"res: %.f", floor(3.000000000001));
//result 3
NSLog(#"res:%.f", floor(3.9999999));
//result 3
If I understand what you want, this code will give you the next even number (up or down depending on which arrow you click), but still allow you to enter non-integer numbers in the text filed. tf and stepper are IBOutlets and num is a property (a float) that keeps track of the value of the stepper before you click an arrow so you can compare with the new number to see if the up or down arrow was clicked.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.num = 0;
self.tf.intValue = 0; //the stepper is set to 0 in IB
}
-(IBAction)textFieldDidChange:(id)sender {
self.num = self.stepper.floatValue = [sender floatValue];
}
-(IBAction)stepperDidChange:(id)sender {
if (self.num < self.stepper.floatValue) { //determines whether the up or down arrow was clicked
self.num = self.stepper.intValue = self.tf.intValue = [self nextLargerEven:self.num];
}else{
self.num = self.stepper.intValue = self.tf.intValue =[self nextSmallerEven:self.num];
}
}
-(int)nextLargerEven:(float) previousValue {
if ((int)previousValue % 2 == 0) {
return (int)previousValue + 2;
}else
return (int)previousValue + 1;
}
-(int)nextSmallerEven:(float) previousValue {
if ((int)previousValue % 2 == 0) {
if ((int)previousValue == previousValue) {
return (int)previousValue - 2;
}else{
return (int)previousValue;
}
}else
return (int)previousValue - 1;
}

How do I compare a constant value to a continuously-updated Accelerometer value each time round a loop?

As it was suggested to me in a previous post of mine, the following code takes the data coming from the accelerometer the "minute" the assignment : CMAccelerometerData* data = [manager accelerometerData]; is performed, and then extracts from that data the acceleration exercised on the x-Axis and stores its value in a double (double x) :
CMMotionManager* manager = [[CMMotionManager alloc] init];
CMAccelerometerData* data = [manager accelerometerData];
double x = [data acceleration].x;
Suppose the value stored is 0.03 and suppose that I want to use it in a while loop as follows :
while (x > 0)
{
// do something
}
the above loop will obviously run forever
However, what if I used the following code instead :
CMMotionManager* manager = [[CMMotionManager alloc] init];
while([[manager accelerometerData] acceleration].x > 0)
{
// do something
}
wouldn't I be now comparing zero to a different value each time round the loop?
(which is what I'm going for in my project anyway..)
any thoughts?
the reason I'm asking this is the following :
I want to check the values coming from the x-Axis over a certain period of time, rather than keep checking them at regular intervals, so I basically want to write a loop that would look something like this :
if ([[manager accelerometerData] acceleration].x > 0 )
{
// initialiseTimer
}
while ([[manager accelerometerData] acceleration].x > 0 )
{
if( checkTimer >=250ms )
{
stopTimer;
printOut("X-Axis acceleration was greater than zero for at least 250ms");
breakFromLoop;
}
}
I know the code in my 2nd if-block isn't valid Objective-C..This was just to give you an idea of what I'm going for..
This has a simple solution.
1)Declare an instance variable x that you update each time the accelerometer tell you to.
2)Compare this x to whatever value you need in the loop .
Hope this helps.
Regards,
George