Decimal keypad Xcode - xcode4.6

I have a text box and a calculate button, I am using a Decimal keypad, when I run my program in the Xcode simulator i get a dot at the bottom left corner but when I run the program in my iPhone i get a comma in the bottom left corner. I know the simulator is set on US Locale and I am in Iceland, I don't get the same outcome if I use the comma instead of the dot. I need to use the dot in my text box, not comma. Is there any code that I can use that tell my program to use dot instead of comma or do I need to make a custom keyboard for this.

Not clear what you're after. If you want to change the way the keyboard looks, then you have to write your own keyboard. But if it is sufficient to respond to the comma by putting a dot in the text field, you can do that easily by intercepting the comma in the text field's delegate. Implement textField:shouldChangeCharactersInRange:replacementString:. Something like this (not tested so you might need to tweak it some):
-(BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string {
if (![string isEqualToString: #","])
return YES;
textField.text =
[textField.text stringByReplacingCharactersInRange:range
withString: #"."];
return NO;
}
If the problem is that the comma is okay, but in countries where the comma is the decimal point, you want it to be used as a decimal point, just use an NSNumberFormatter when you pull the string out of the text field and turn it into a number. Right now you are doing this by saying [_PipeID.text floatValue]. That call has no intelligence about the locale. NSNumberFormatter does:
NSNumberFormatter* nf = [[NSNumberFormatter alloc] init];
nf.locale = [NSLocale currentLocale];
NSNumber* n = [nf numberFromString: tf.text];
// and *then* you can convert the NSNumber to a float with `floatValue`
NSLog(#"%f",n.floatValue);
By the way, you said:
when I run my program in the Xcode simulator ... but when I run the program in my iPhone
But you can test this perfectly well on the Simulator; just use the Settings app to set the language and region formatting.

float s2 = [[dist.text stringByReplacingOccurrencesOfString:#"," withString:#"."] floatValue];
dist.text = [[NSString alloc] initWithFormat:#"%0.02f", s2];

Related

Tizen native wearable - how to add text label auto line break?

I want to show a full line of long text in a label. But when it is small in character numbers It can show it in full. But when the character number grows it shows some part of the texts. Even if I add size to it. It can show line break with html formats but I will perform character operation with network calls, so instead of checking individual characters or keeping track of numbers it will be better if it can add auto line break at the end of screen and show all the texts on screen.
Here's code for label:
ad->label = elm_label_add(ad->conform);
elm_object_text_set(ad->label, "<align=center>Hello Tizen , line is cut offfffffffffffff.</align>");
//elm_object_text_set(ad->label, "<align=center>Hello Tizen <br>testing br</align>");
evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
//elm_object_content_set(ad->conform, ad->label);
evas_object_move(ad->label, 20, 100);
evas_object_resize(ad->label, 300, 300);
evas_object_show(ad->label);
How to add auto line break?
Try using elm_label_line_wrap_set API.
elm_label_line_wrap_set(ad->label, ELM_WRAP_MIXED);
See the API reference below.
void elm_label_line_wrap_set ( Elm_Label *obj,
Elm_Wrap_Type wrap
)
Control the wrapping behavior of the label.
By default no wrapping is done. Possible values for wrap are: ELM_WRAP_NONE - No wrapping ELM_WRAP_CHAR - wrap between characters ELM_WRAP_WORD - wrap between words ELM_WRAP_MIXED - Word wrap, and if that fails, char wrap
https://docs.tizen.org/iot/api/5.0/tizen-iot-headed/group__Elm__Label.html#ga60a1dad4d49a3aea31ced12e30d0b815

Overriding Ext.util.Format.thousandSeparator except when formatting money

I am trying to override Ext.util.Format.decimalSeparator and thousandSeparator. So, in my app, when I chnage the language to Spanish and I try using this function, Ext.util.Format.number(1234,'$0,000'), still it converts the number to 1.234 instead of 1,234.
I want that, irrespective of what language I choose, it should always format the money to $0,000 format and not using my selected locale, e.g., never $0.000. I observed if I change the thousandSeparator of Ext.util.Format object, it works fine. So, I added the following code in Ext.Loader.loadScript callback function in launch function in Application.js,
var utilFormatObj={};
utilFormatObj.thousandSeparator = ",";
utilFormatObj.decimalSeparator = ".";
Ext.override(Ext.util.Format, utilFormatObj);
BUt, it seems to work only in this place, once it loads the app on webpage, it again gets back to thousandSeparator=".". I can see that ext-lang-es.js file has the function which sets these properties. Can anyone suggest how can I catch whether the app is completely loaded on webapge and then use the above code there. Thank you.
When you call Ext.util.Format.number() you're not specifying what to use as decimal or thousand separator, you're only specifying precision, whether to show thousands separator, and whether to pad precision with zeroes.
The documentation for Ext.util.Format.number states:
The format string must specify separator characters according to US/UK conventions ("," as the thousand separator, and "." as the decimal separator)
Therefore if you want to display numbers in different locales, you have to run the code that changes the default separators before calling Ext.util.Format.number or Ext.util.Format.currency.
var value = 202020.20, format = "0,000.0000";
// Print in Spanish
Ext.util.Format.thousandSeparator = ".";
Ext.util.Format.decimalSeparator = ",";
alert(Ext.util.Format.number(value, format));
// Print in Swedish French
Ext.util.Format.thousandSeparator = "'";
Ext.util.Format.decimalSeparator = ",";
alert(Ext.util.Format.number(value, format));
// Print in English
Ext.util.Format.thousandSeparator = ",";
Ext.util.Format.decimalSeparator = ".";
alert(Ext.util.Format.number(value, format));
Here's a hack you can use if you really want to specify that currency should always use a period as the thousand separator but still have Ext.util.Format.number use the selected locale's separators.
function formatMoney(amount, sign, decimals, end) {
// Save the thousand separator
var thousandSep = Ext.util.Format.thousandSeparator;
Ext.util.Format.thousandSeparator = '.';
var formatted = Ext.util.Format.currency(amount, sign, decimals, end);
// restore the thousand separator
Ext.util.Format.thousandSeparator = thousandSep;
return formatted;
}
Example for the above code snippets: https://fiddle.sencha.com/#fiddle/9vm
I am guessing that you are not using the loader after you build your application for deployment. Typically the dynamic loader is only used for development (so you can see each script individually) and you use a faster method in prod.
You could load your Ext overrides on the callback for Ext.define:
Ext.define( className, data, [createdFn] )
where createdFn is a function that contains your Ext overrides. This approach may lend itself to race conditions if you invoke that Format object before the override is applied. To be confident, you could add another JS file with your overrides (after Ext is loaded, before your app code) and make sure that is included when you load your app.

SpeechSynthesizer audio to text as its spoken

I Am currently working on a project where I want to have the SpeechSynthesizer speak a text. I also want a textblock to display the words as they are spoken. This is so you can read along if you don't understand the Speech Synthesizer.
So basically the problem is that i cant find a efficient way to append every letter to a text within a textbox right when its spoken by the Speech Synthesizer. So it looks like the Speech Synthesizer is typing along with what he is saying.
Example
If I would do this:
SpeechSynthesizer x = new SpeechSynthesizer();
x.SpeakAsync("Hello there");
I want the textbox text to write along as the words are spoken by the x (SpeechSynthesizer ). Something like this:
http://youtu.be/hx6JL7PsLrg?t=1m56s
As Eric mentioned, you have to use the SpeechSynthesizer.SpeakProgress event:
For Example:
var ss = new SpeechSynthesizer();
ss.SpeakProgress += (sender, args) => txtBox.Text += args.Text;
ss.Speak("Hello this is " + true);
This is kind of hacky (and isn't guaranteed to do letter-by-letter), but you could use the PhonemeReached event as a hint to display the next letter (and stop at word breaks) and then use the SpeakProgress event to generate the remaining letters in the word. If you're using SSML, you'll need to skip over markup, of course.

How do you create a UIAlertView based on the text in a UITextField?

I want to enter text into a text field and based on the text (if it says "No") I want the alertview to pop up. I've created a UITextField in interface builder and attached it to the UITextField delegate in the files owner so that's all taken care of. But when I enter text into the text field, specifically no, and click out of the textfield or remove the keyboard, no alertview pops up. I have created an entire method for this within the viewcontroller.m file. Here is the code for that method.
-(void)engageAlert {
if (myTextField.text == #"No") {
theAlertView = [[UIAlertView alloc] initWithTitle:#"Notice" message:#"MyMessageHere"
delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[theAlertView show];
}
}
Am I missing something here? Nothing happens when I type No into the textfield.
I think the culprit will be the line
myTextField.text == #"No"
Since you're comparing two pointers which will never match.
#"No" = 0x12341234 or whatever address for the static address of the NSString (#"" can be thought of as short hand for the compiler creating the NSString object)
What you will want is something like
if( [myTextField.text isEqualToString:#"No"])
Also check you're not going to leak memory with theAlertView as I can't see where you're freeing that in the snippet.

Custom heightForRowAtIndexPath (CGSize sizeWithFont) with NSAttributedString iOS

I have a table view where my cells height is defined dynamically depending on the text it is representing.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//getting my text for this cell, the row etc ...
...
//here is the part interesting us
NSAttributedString* theText = [myTextForThisCell objectAtIndex:indexPath.row];
NSInteger labelWidth = self.tableView.bounds.size.width-HORIZONTAL_CELL_PADDING;
CGSize textSize = [theText sizeWithFont:[UIFont systemFontOfSize:customFontSize] constrainedToSize:CGSizeMake(labelWidth, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
return textSize.height+VERTICAL_CELL_PADDING;
}
Ok so now my problem.
The tableview is the result of a search action which after scanning a plist file shows the lines containing a given string.
Up to now that was it. But now with iOS 6 and NSAttributedString allowing easily to bold part of strings I decided to bold the search word.
It is working, it bolds the words I want but now I am no more able to calculate the cell height as sizeWithFont ask for a NSString. And as bolding takes a wider width I cannot simply calculate the cell height with the string without attributes.
I am simply stuck here.
Anyone can help me ?
In fact I simply had to read apple documentation of NSAttributedText.
In my case I have to replace the last two lines of code by
CGRect rectSize = [theText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin context:NULL];
return rectSize.size.height+VERTICAL_CELL_PADDING;
FOLLOW UP iOS 7
I have been struggling making this work in iOS7 with attributed text.
Apple documentation says
In iOS 7 and later, this method returns fractional sizes (in the size
component of the returned CGRect); to use a returned size to size
views, you must use raise its value to the nearest higher integer
using the ceil function.
Which way obviously not working for me ! For me the solution was to add +1 to the ceil of height. This is probably a bug from Apple, but for me now everything works as in iOS6.
CGRect rectSize = [theAttributedText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin context:NULL];
return ceil(rectSize.size.height) + 1 + VERTICAL_CELL_PADDING;

Resources