Adding text to an already populated UITextView - ios

Really quick, easy question.How do I add text to a UITextView, when it's already populated.
E.G., but doesn't work: _textView.text=+#"";
Thanks,
SebOH

_textView.text = [_textView.text stringByAppendingString:#""]

_textView.text = [_textView.text stringByAppendingString:#"Additional Text"];

_textView.text = [NSString stringWithFormat:#"%#%#",_textView.text,#"text you want to append"];
using above you can add the text where ever you want prefix,postfix ..

Related

ios 8 UITextView UIDataDetectorTypeLink not working

I am setting html text to UITextView and set UIDataDetectorTypeLink to DataDetectorTypes but its not working.below is code:`
self.dictHelp =[NSMutableDictionary dictionaryWithDictionary:response];
[self.txtView setValue:[self.dictHelp valueForKey:#"HelpText"] forKey:#"contentToHTMLString"];
self.txtView.userInteractionEnabled = YES;
[self.txtView setDataDetectorTypes:UIDataDetectorTypeLink];`
Text value is "If you need assistance please contact XXXX at customerservice#xxxx.org"
what am i doing wrong?
Just check this code, I found in this Link:- It's a work around but it works nice!
self.txtView.selectable = NO; // set it to NO clears all possible data detection work so far.
self.txtView.selectable = YES; // set it to YES so that actual links are detected.
Please try with below way -
self.txtView.text = nil;
[self.txtView setValue:nil forKey:#"contentToHTMLString"];
[self.txtView setValue:[self.dictHelp valueForKey:#"HelpText"] forKey:#"contentToHTMLString"];

How to create a custom software key UITextField/NSTextField

I want to create a custom NSTextField/UITextField like this for entering a software key (pardon my paint skills).
Does anybody have any suggestions as to how I should go about this?
My lazy solution would be to give it a placeholder string with spaces and dashes in between, and as they type just mask those dashes into their string. But I wanted to see if anybody else had some input-- or if I should just go with your standard separate text fields
-(void)viewDidLoad
{
UITextField *firstPart = [[UITextField alloc] initWithFrame: YOUR_FRAME];
firstPart.placeholder = #"-";
firstPart.textAlignment = NSTextAlignmentCenter;
[self.view addSubview: firstPart];
// Create others
}
-(IBAction)unlockBtnPressed:(id)sender
{
NSString *softwareKey = [NSString stringWithFormat: #"%# - %# - %#", firstPart.text, secondPart.text, thirdPart.text];
}

ios check if text is too big for uiTextfield

This question is not about UITextView: It's about UITextField.
How do I check if my text would be too long for my UITextField? I need to dynamically change the Height of my UITextField so that it accepts multiple lines. Is this possible or must I use a UITextView for this? I prefer UITextField because of the convenience of a placeholder text.
You can use
sizeWithFont:
of NSString to avaluate the length of a string.
UITextField is not able to show multiple lines. For solutions take a look at
Objective C: How to create a multi-line UITextField?
Claus
Hi just use small trick for this code sample below.
+ (CGFloat)expectedHeightWithData:(MECommentData *)data
{
#autoreleasepool
{
NSString *comment = data.comment;
UIFont *commentSizeFont = [UIFont fontWithName:#"Miso-Bold" size: 15.0];
CGSize commentSize = [NSString sizeWithFont:commentSizeFont width:225 heitght:3000 text:comment];
return ceilf(commentSize.height);
}
}

How to keep Placeholders even after clearing all textfields

So I have 3 textfields. After they are cleared, I would like the placeholder to STILL remain there. So far for about the past week I've been fighting with this issue and no one is able to help me solve it. I was wondering if this is even possible?...
Here is my sample code to set the placeholder after clearing it:
personYouOweMoney.text = #" ";
amtYouOwe.text = #" ";
self.cellNum.text = #" ";
personYouOweMoney.placeholder = #"Name of person you owe";
amtYouOwe.placeholder = #"Amount Owed (USD)";
self.cellNum.placeholder = #"Their cell number";
All help is appreciated, thanks in advance
You are basically setting the textField's text to a single space so, technically, it ain't empty.
(Only when the textField is empty will the placeholder will be seen)
Do:
//set the placeholder's and when you want to clear the textfield, this...
personYouOweMoney.text = #"";
amtYouOwe.text = #"";
self.cellNum.text = #"";

UILabel not getting what I write to it

Tricky to write the subject to this. I guess this is a basic question but I can't seem to find the answer.
The code itself shows what I wanna do and the UILabel don't show anything, the first line I add to it works fine, but not when I try to write out the array:
-(IBAction)getSongHistory:(id)sender {
[historyLabel setText:#"test write\n test write another line"];
NSArray *pastMusicArray = [pastSongs getHistory];
for(int t=2; t<[pastMusicArray count]; t++) {
NSString *tempRow = [pastMusicArray objectAtIndex:t];
//NSLog(#"%#", tempRow);
[historyLabel setText:tempRow];
[historyLabel setText:#"\n"];
}
}
The NSLog do put out the right stuff.
What is gong on here, that I am not seeing?
Seems to me that the problem is that you are setting the full text each time and the last setText: is with #"\n" which is an invisible string. Try appending instead of setting the text. Something like:
historyLabel.text = [NSString stringWithFormat:#"%#%#", historyLabel.text,#"TextToAppend"];
This will append #"TextToAppend" to the current text value in the label.
Update: Notice I'm using the text property rather than the setter.
historyLabel.text = #"Some Text";
is equivalent to
[historyLabel setText:#"Some Text"];
Using \n in a string should be fine, try to set numberOfLines property of the label to 0, which allow any number of lines in it.
This is the solution for my own problem. Hope that it can help someone else.
NSArray *pastMusicArray = [pastSongs getHistory];
musicHistory = [[NSMutableString alloc] init];
historyLabel.numberOfLines = 0;
for(int t=2; t<[pastMusicArray count]; t++) {
[musicHistory appendString:[[pastMusicArray objectAtIndex:t] capitalizedString]];
[musicHistory appendString:#"\n"];
}
historyLabel.text = musicHistory;

Resources