Hello I want to achieve the following.
So far everything went good by using the docs. However, I can't seem to set a value on top like € 230 or € 70. When I use the
barChartView.drawValueAboveBarEnabled = true
Because it sets the value of the bar charts ( 70, 30 etc)
Is it possible to do this? :)
each dataSet has a value formater, use it to format your value like below should be enough:
set1.valueFormatter = [[NSNumberFormatter alloc] init];
set1.valueFormatter.negativePrefix = #"€ ";
set1.valueFormatter.positivePrefix = #"€ ";
Related
I have been attempting to Add the values of some UI labels in Xcode, but with '+' there is an error and I have not found any other way yet to have it work.
Storyboard
ViewController.Swift
It‘s not clear in your question but I think you’re trying to change the text displayed by the UILabel. If this is the case, you can do this as following
myLabel.text = “myText”
or
myLabel.text += “Test”
You have to be more specific. I don’t really get what you want to add so I will assume.
If you want to add the Strings the UILabels contain, you should do as Bruce said above.
If you want to add the two strings into a variable you should do this.
Var outcome = label1.text + label2.text
The outcome would be the string of label one plus the string of label two connected.
Now if the labels contain numbers and you want to add those numbers you should do this. (Assuming they do contain Integers)
let num1 = label1.text.toInt()
let num2 = label2.text.toInt()
let outcome = num1 + num2
In your case it would be....:
Let sumOfIntegers = MathCriAValue.text.toInt() + MathCriBValue.text.toInt() + MathCriCValue.text.toInt() + MathCriDValue.text.toInt()
I am creating an OS X app and when I do this:
var tempVal = 10495.33
tempTextField.doubleValue = self.tempVal
It shows like this: 10,495.33. Notice the comma.
Now when I modify that value to 30,400.34 in the NSTextField and try to assign it back to the doubleValue things get messed up.
tempVal = tempTextField.doubleValue //Now this makes tempVal = 30 instead of 30,400.34
This is all because of the comma. Without the comma things are fine.
I know there is a bad fix where I just remove all commas from the number string but I feel like there is a better/correct way to do this.
The issue is most likely cause by by your system settings. Apparently (do not kwon why) you should enter the numbers in a US like format (using a "." as decimal separator), but the output to the textfield is depending on your system setting. So if you are in Europe most likely you use "," as a decimal separator
you can fix it as follows (you configure the format of the NSTextField, so no need to format the data you enter)
//This codes works in swift 4
//This should be your textfield. It is either programmed or you link it through storyboard
var myTextField = NSTextField()
//This is a formatter. You can set it up how to format the textfield
var myFormat = NumberFormatter()
myFormat.decimalSeparator = "."
myFormat.numberStyle = .decimal
//Now you connect the two
myTextField.formatter = myFormat
This seems like a very easy question but I can't seem to work it out. Basically I have a number of cells: Face1, Face2, Scene1, Scene2. Each cell contains a value, for instance, Face1=15, Face2=23, Scene1=46, Scene2=9
Now I would like to group all these cells into one single cell called D, something like this D={Face1,Face2,Scene1,Scene2}. However, when I do this I get D={15,23,46,9}. This is not what I want. I'd like to keep the identity of each cell so when I call D{1,1} I'll get Face1, and when I call Face1, I'll get 15.
Does anyone have a suggestion?
Thanks!
Have you considered using structures? Try this:
D.face1 = 15
D.face2 = 23
You could also do it like this:
D.face(1) = 15
Let me know if that doesn't do it for you.
Probably not the best "solution", but you could do something with eval.
First, create your variables.
Face1 = 15, Face2 = 23, Scene1 = 46, Scene2 = 9
Then, create the cell array containing the variable names, as strings:
D = {'Face1', 'Face2', 'Scene1', 'Scene2'}
You can query their values like this:
>> eval(D{1,1})
Face1 =
15
Too long for a comment:
Looks like you are using arrays, not cells. That is, I think your code looks like this:
Face1 = 15
Face2 = 23
Scene1 = 46
Scene2 = 9
D = {Face1 Face2 Scene1 Scene2}
Which would act as you describe. Now D{1} returns 15.
If you were using "cells", your code would look like this:
Face1 = {15}
Face2 = {23}
Scene1 = {46}
Scene2 = {9}
D = {Face1 Face2 Scene1 Scene2}
This is probably not what you want, but it is the cell solution. Now D{1} returns {15} and D{1}{1} returns 15.
If you want to preserve the names in the composite data D, the a struct is probably the easiest thing. See Fletch's just-posted answer.
I am looking to create an iOS calculator, just by using a UITextField. So for example; somebody may type in '6 - 3 x 2' in the UITextField then hit "Done" or "Go" etc. This would then calculate the answer and display it in a UIAlertView.
So firstly I believe that the UITextField text has to be split up into different sections so '6' '-' '3' '*' '2' would be the separated strings from the UITextField text input. How would I go about separating the text like mentioned above?
How can I then use this information to calculate the answer and to display it?
Use GCMathParser http://apptree.net/parser.htm
It takes an NSString as an input and evaluates it for you.
As Danh said, you can also use DDMathParser https://github.com/davedelong/DDMathParser
An Example(right from the docs)
NSString* mathstring = #"tan(dtor(45))";
double result = [mathstring evaluateMath]; // returns 0.999999999999...
So you simply send message evaluateMath to the NSString you want to parse. That's it)
You could also use NSPredicate as such:
NSPredicate * parsed = [NSPredicate predicateWithFormat:#"22/7.0 + (13*42) - 1024 = 0"];
NSExpression * left = [(NSComparisonPredicate *)parsed leftExpression];
NSNumber * result = [left expressionValueWithObject:nil context:nil];
NSLog(#"result: %#", result);
But I'm not sure about functions like tan and such. More info here.
Im trying to do something that I think is super simple.
i have 3 integers - prevgues1 , 2 and 3
and i have 3 UILabels prevguess1, 2 and 3
the ints have 1 less s.
When I set the text of the label so
prevguess1.text = [NSString stringWithFormat:#"%d", prevguess1]
prevguess2.text = [NSString stringWithFormat:#"%d", prevguess2];
prevguess3.text = [NSString stringWithFormat:#"%d", prevguess3];
the label just set to a number like 89324 or something like that.
I just don't know what my problem is.
Any ideas would be helpful
Cheers
Sam
Note:
I have tried setting the text simply to a string - and have had luck.
but when i set it to a integer, which start as 0 value, (in viewdidload) the weirdness happens
prevguess1.text = [NSString stringWithFormat:#"%d", prevguess1];
Here you treat prevguess1 as a label and as an integer - probably there's a typo somewhere?
Even if it's not a matter of your problems I think you should consider changing the way you name your variables a bit to avoid possible confusion.