If using Xcode to make an iOS calculator, how would I add a decimal button? - iphone

How to add a decimal button so I don't have to do whole numbers? If i wanted any decimal number like 1.2 or 100.4 or 3.0 or anything like that, how would I add it to the calculator I'm making?

You're not giving me much information in your question. How do the other buttons work?
If I was making a calculator I would have a label at the top showing the current reading. On press of a number button I would update the label with the number at the end.
For a decimal button you just add a . to the end of the label. You might want to have a global variable BOOL hasDecimalPlace and set it to true so you know if there is already a decimal place. Just remember to set it to false again when you clear the view or do a calculation or similar.

- (IBAction)Decimal:(id)sender{
NSString *currentText = Text.text;
if ([currentText rangeOfString:#"." options:NSBackwardsSearch].length == 0) {
Text.text = [Text.text stringByAppendingString:#"."];
}
}

Related

Is there a way to move the cursor of TextField to the end of the text when editing?- SwiftUI

I have created a textfield in Swift UI and I'm looking for a way to make the cursor of the textfield on editing to be at the end of the text even if I tapped the first letter on the textfield.
I think you mean something like this, to set .endOfDocument:
let endPosition = textField.endOfDocument
textField.selectedTextRange = textField.textRange(from: endPosition, to: endPosition)
Now it will stay at the end of the position. If you search something more advanced, I recommend you this post and its answer.

Toggle hide UITextField with fixed number of dot

Currently, i'm using the code below but there is a problem that the last part of the text is ... instead of *** (see picture). Now I want to hide text with only six * like ****** and figure out how to fix the problem above.
#objc func hideMoney(){
if isMoneyHide == true{
moneyAmount.isSecureTextEntry = true
}else{
moneyAmount.isSecureTextEntry = false
}
isMoneyHide = !isMoneyHide
}
The result:
Thank in advance
To solve the issue
Set minimum font size to lower than your UITextField text size
Example: - If your UITextField text size is 20 then minimum font size set to 15

Swift - UITextView maxLines is set but can type beyond

I have a UITextView that has maxLines set like this:
textView.textContainer.maximumNumberOfLines = 3;
textView.textContainer.lineBreakMode = .byTruncatingTail
textView.isScrollEnabled = false
However, when typing in the textView, you can press return several times and type beyond 3 lines. Visually, only 3 lines appear, but as you type text is being entered on and on. Is there a way to prevent this?
The maximum number of lines is used to define how many will be visible in the interface. This has nothing to do with the amount of text you type.
If you want to add a "limit" to the number of characters you have to do it programmatically.
There are several other answers related to this on SO.
How to limit characters in UITextView iOS
You can try this
textView.textContainer.maximumNumberOfLines = 3
textView.textContainer.lineBreakMode = .byTruncatingTail
textView.layoutManager.textContainerChangedGeometry(textView.textContainer)

IOS-Charts set maximum visible x axis values

I'm using ios-charts (https://github.com/danielgindi/Charts). I have a LineChartView with 12 values in the x axis.
This however is far too many to see at the same time, so I want to display only 5 and then let the user drag to the right to see the next.
I've tried this:
let chart = LineChartView()
chart.dragEnabled = true
chart.setVisibleXRangeMaximum(5)
let xAxis = chart.xAxis
xAxis.axisMinValue = 0
xAxis.axisMaxValue = 5.0
xAxis.setLabelsToSkip(0)
But still see all 11 values at the time. How can I only see 5?
I finally got it!
The correct answer is:
chart.setVisibleXRangeMaximum(5)
This however needs to be set after the data has been set in the chart (not in a configure before)
This did the trick for me
You should set the X axis's labelCount property of the chart view.
In objc,like this
_chartView.xAxis.labelCount = 5;
Swift
chartView.xAxis.labelCount = 5
Here is my finding!!
you don't need to really use label count
if you are using DefaultAxisValueFormatter, NEVER use this. a lot of errors pop ! just use no2.
chart.setVisibleXRangeMaximum(number) will do.
please put this after chart data setting here you can see detail
combinedChartView.data = combineData. //this need to come first
combinedChartView.setVisibleXRangeMaximum(2) //after data setting

How to make jbutton sum up the values of my jradiobuttons

I'm making a project in jFrame. It has 15 jRadiobuttons. What I want is a jButton to add the selected jRadioButtons and display the sum in a jTextField. Can anyone help me? I've been doing this for 3 days and cant get it right.
So you have numbers as values of the radiobuttons?
Then try it like this:
When the button is clicked, go through a foreach loop of all radiobuttons.
in the loop, check if they are selected. If they are, you add their value to the Sum.
Is that what you were asking for?
EDIT
You create A List containing all radiobuttons.
In the Listener of the Button you write:
int sum = 0;
//foreach loop
for (jRadiobutton rbutton : rbuttons){
//Check if the button is selected
if (rbutton.isSelected){
sum += rbutton.Value;
}
}
I hope this is good enough explained.
Maybe the Syntax isn't correct, i haven't used java for a while now...