UITextView not loading/showing the large text? - ios

I have a simple UITextView in my login screen where I need to display Terms & conditions.I have a very large text in Terms and Conditions.In the interface builder I have added text to the UITextView. In the interface builder the text is getting showed properly. But when I run the application the UITextView is empty. If I give small text in the UItextView it is rendering properly but huge/large text is not getting displayed.
Here is the code.
- (IBAction)showTermsOfUse:(id)sender{
termsOfUseText.text = #"/***/";
termsOfUseText.scrollEnabled = YES;
[UIView beginAnimations:nil context:nil]; // begins animation block
[UIView setAnimationDuration:0.6]; // sets animation duration
[UIView setAnimationDelegate:self];
termsOfUse.frame = CGRectMake(0,0,320,416);
[UIView commitAnimations]; // commits the animation block. This Block is done.
}

I also had faced the same problem and i solved it my taking IBOutlet of UITextView and setting the value in the code like this
UITextView *txtView=[[UITextView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
[txtView setText:#"Your long text"];
[txtView setEditable:NO];
[self.view addSubview:txtView];
[txtView release];
Another option can be take a webview and load your contents in webview.

Create this UITextView programmatically
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(AsYouNeed)];
[textView setFont: [UIFont fontWithName:#"YourFontName" size:YourSize]];
textView.text = #"test my font size";
[textview setUserInteractionEnabled:TRUE];
[self.view addSubview:textView];
[textView release];

By giving the text programmatically....and
termsofUseText.text = #"MY LARGE TEXT GOES HERE...... "
termsOfUseText.scrollEnabled = YES;
termsOfUseText.userInteractionEnabled = YES;
termsOfUseText.editable = NO;

Related

Add UITextField above keyboard iOS

In my app I'm trying to add a UITextField on a accessoryView. It should work as follow:
I press on a UITextField in the user interface of app
The keyboard pop up and cover my UITextField on the user interface
To edit text I wanted to show a UITextField in an accessoryView just above the keyboard
I looked on the web but I found only stuff to add button on an accessoryView, I hope you can help me to find a solution to add an UITextField on an accessoryView.
Thank you
UPDATE
This is what I mean:
I hope you understand better my question, I'm not looking for a solution that should user scroll view or something, I don't want to change the interface of my app...
in .h
UIView *customtoolbar;
in .m At viewdidload add thi code
customtoolbar=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height+50, 320, 50)];`
after this add this methods
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self pressdone];
return YES;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//216 is keyboard default height in portrait(162 in landscape)
[UIView animateWithDuration:0.7 animations:^{
[self addtoolbar:CGRectMake(0, self.view.frame.size.height-216-50, 320, 50)];
}];
return YES;
}
-(UIView *)addtoolbar:(CGRect )frame{
customtoolbar.frame=frame;
customtoolbar.backgroundColor=[UIColor darkGrayColor];
//give new frame to your textfield
txtfld.frame=CGRectMake(5,10, 220, 30);
[customtoolbar addSubview:txtfld];
UIButton *done=[UIButton buttonWithType:UIButtonTypeCustom];
done.frame=CGRectMake(235,10, 60, 30);
[done setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[done setTitle:#"Done" forState:UIControlStateNormal];
[done addTarget:self action:#selector(pressdone) forControlEvents:UIControlEventTouchUpInside];
[customtoolbar addSubview:done];
[self.view addSubview:customtoolbar];
return customtoolbar;
}
-(void)pressdone{
[self addtoolbar:CGRectMake(0, self.view.frame.size.height+50, 320, 50)];
//set there orignal frame of your textfield
txtfld.frame=CGRectMake(95, 170, 123, 37);
[self.view addSubview:txtfld];
[txtfld resignFirstResponder];
}
Add a view and then on top of it, please put a textfield and try. Below is the code.
UIView * container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
[container setBackgroundColor:[UIColor redColor]];
UITextField * newTextfield = [[UITextField alloc] initWithFrame:CGRectMake(50, 0, 100, 44)];
[newTextfield setBackgroundColor:[UIColor yellowColor]];
[container addSubview:newTextfield];
self.textField.inputAccessoryView = container;
This contains some colors, just to distinguish and identify the views. Change and format according to your needs. It will work. :)
you can use scroll view for this in your app & set content offset
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.scroll.contentOffset = CGPointMake(0, textField.frame.origin.y);
}
i hope this is relevent to your problem
This is what i have done in my apps
Add observers to UIKeyboardWillHideNotification & UIKeyboardWillShowNotification
When u review notification resize your view keyboardFrame
double duration = [[notification userInfo][UIKeyboardAnimationDurationUserInfoKey] doubleValue];
int curve = [[notification userInfo][UIKeyboardAnimationCurveUserInfoKey] intValue];
NSValue *value = [notification userInfo][UIKeyboardFrameEndUserInfoKey];
CGRect rawFrame = [value CGRectValue];
CGRect keyboardFrame = [self.view convertRect:rawFrame fromView:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
// Resize your View
[UIView commitAnimations]

UITextView Not responding

I am using textview in my code using the below code
UITextView *ObservationTextView3=[[UITextView alloc]init];
ObservationTextView3.frame=CGRectMake(45, ObservationLabel3.frame.origin.y+ObservationLabel3.frame.size.height, 410, 70);
[ObservationTextView3 setKeyboardType:UIKeyboardTypeDefault];
ObservationTextView3.font=[UIFont fontWithName:#"Helvetica" size:14];
ObservationTextView3.delegate=self;
ObservationTextView3.tag=139;
ObservationTextView3.text = #"";
ObservationTextView3.layer.borderWidth=1.0f;
ObservationTextView3.layer.borderColor=[UIColor lightGrayColor].CGColor;
ObservationTextView3.layer.cornerRadius=4.0f;
[_BeverageRoutineScroll addSubview:ObservationTextView3];
but i am unable to make this textview respond i've tried many things but evrything goes invane.
please help me out.
Try this:
[self.view bringSubviewToFront:yourTextView];
[self.view sendSubViewToBack:yourScrollview];
OR
[self.yourScrollView setUserInteractionEnabled:YES];
[self.yourTextView setUserInteractionEnabled:YES];
OR
check your scrollView's Content Size and Text View Frame

How to present 'UIViewController' in Cocoas2D with custom size

Imagine I have dialog and size of this dialog is 200x200 and I want to present on the iPhone screen temporary (can dismiss with button).
I try it. but the view controller that I presented is replace current scene (dialog and white background border).
I want to present with custom size (200x200) at center of iPhone screen and see my content as background
I try to set dialog's background colour to clearColor and It doesn't work.
Thanks in advance.
Create your button like this,
[button addTarget:self action:#selector(ButtonFun) forControlEvents:UIControlEventTouchUpInside];
-(void)ButtonFun {
UIView *newView1 = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
newView1.backgroundColor = [UIColor whiteColor];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
textView.text = #"Write your dialog";
[textView setFont:[UIFont fontWithName:#"ArialMT" size:15]];
textView.textAlignment = NSTextAlignmentCenter;
[newView1 addSubview:textView];
newView1.center = self.view.center;
[self.view addSubview:newView1];
}
To remove this UIView use UITapGestureRecognizer,or simply
[newView1 removeFromSuperview];

How to have a page with long text that is wrapped automatically based on the phone screen

I am trying to make a book application. I am stucked with the text that can show long string. Basically, I tried to use UI Label, but it is only showing one line and the remaining of the text is cut.
Any idea what kind of UI that I should use to make a book? Thanks.
Set the numberOfLines for the UILabel to 0, to let it use as many lines as it needs.
You have to use UITextView for such purpose check
UITextView *aboutStable = [[UITextView alloc] init];
[aboutStable setFont:[UIFont fontWithName:#"Helvetica" size:12]];
[aboutStable setText:#"Write your long text here............iphonemaclover is great"];
[aboutStable setTextColor:[UIColor grayColor]];
[aboutStable setBackgroundColor:[UIColor clearColor]];
[aboutStable setTextAlignment:UITextAlignmentCenter];
[aboutStable setFrame:CGRectMake(0, 302, 320, 79)];
[self addSubview:aboutStable];
And make it not editable so set
[aboutStable setUserInteractionEnabled:NO]
should do it
and if you need scrolling:
aboutStable.editable = NO;
or if you text is still more,then you can set scrollview in it too...
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 195, 280, 10)];
textView.text = #"your long text here";
textView.font = [UIFont fontWithName:#"Hevlatica" size:14];
[self.scrollView addSubview:textView];//add scrollview using Xib and set property of it.
CGRect descriptionFrame = textView.frame;
descriptionFrame.size.height = textView.contentSize.height;
textView.frame = descriptionFrame;
or you can check more detail here in this sample code
EDIT FOR DIFFERENT RETINA DISPLAY
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (screenRect.size.height == 568.0f)
{
//condition for iphone 5 screen
}
else
{
//condition for retina display 3.5
}

iPhone: UITextView not expanding while editing

I am using UITextView on a scroll view ...and I want it to auto expand when I write something in it ...... but I am unable to do it ...
textViewBusiness = [[UITextView alloc] initWithFrame:CGRectMake(25,332,268,60)];
textViewBusiness.text=strMyBusiness;
textViewBusiness.editable=NO;
textViewBusiness.font = [UIFont fontWithName:#"Arial" size: 17.0];
textViewBusiness.layer.borderWidth = 2.0f;
textViewBusiness.layer.borderColor = [[UIColor grayColor] CGColor];
textViewBusiness.backgroundColor = [UIColor clearColor];
[textViewBusiness setTextColor:[UIColor blackColor]];
[self.scrollView addSubview: textViewBusiness];
CGRect frame = textViewBusiness.frame;
frame.size.height = textViewBusiness.contentSize.height;
textViewBusiness.frame = frame;
This code is not working for me ...
Thanks
Make sure the text field's delegate is set...
someTextField.delegate = self;
Then adjust the size of the textView in the appropriate text field delegate method.
- (void)textViewDidChange:(UITextView *)textView;
- (void) textViewDidEndEditing:(UITextView *)textView;
The code you've added above is correct. Just make sure it's in the correct place.
- (void)textViewDidChange:(UITextView *)textView
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
}
Dynamic expand UITextView
Your code won't work.
You need to divide your code into 2 fragments, then place them into proper places, then your code should work.
Fragment 1 (in my test, I place this fragment in viewDidLoad):
textViewBusiness = [[UITextView alloc] initWithFrame:CGRectMake(25,332,268,60)];
textViewBusiness.text=strMyBusiness;
textViewBusiness.editable=NO;
textViewBusiness.font = [UIFont fontWithName:#"Arial" size: 17.0];
textViewBusiness.layer.borderWidth = 2.0f;
textViewBusiness.layer.borderColor = [[UIColor grayColor] CGColor];
textViewBusiness.backgroundColor = [UIColor clearColor];
[textViewBusiness setTextColor:[UIColor blackColor]];
[self.scrollView addSubview: textViewBusiness];
Ensure that the above fragment run, and your text view is displayed in the screen, then run the second fragment. If your text view is not displayed in the screen, then the contentView is not initialized, and the height is undefined.
Fragment 2 (in my test, I place this fragment in viewDidAppear):
CGRect frame = textViewBusiness.frame;
frame.size.height = textViewBusiness.contentSize.height;
textViewBusiness.frame = frame;
Good luck!
HPGrowingTextView is a UITextView which grows/shrinks with the text and starts scrolling when the content reaches a certain number of lines. Similar to the one Apple uses in the SMS-app. See the link for a small (outdated) screencast.

Resources