UITextView Not responding - ios

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

Related

iOS UITextView sizeToFit make height doubled of content text in iPad

Below is my code of textView, but sizeToFit makes textView's height more than doubled of it's content text. Please provide any solution
UITextView *paragraphView = [[UITextView alloc] initWithFrame: CGRectMake(10, 10, 295, 30)];
[paragraphView setContentMode: UIViewContentModeScaleToFill];
[paragraphView setScrollEnabled: NO];
[paragraphView setEditable: NO];
[paragraphView setText: #"hello there ..........hii i am here....."];
[paragraphView setFont: [UIFont systemFontOfSize: 30]];
[self.view addSubview: paragraphView];
[paragraphView sizeToFit];
Try using NSLayout constraints to frame the UITextview instead of initwithframe.
you may get the content sized height for textview properly

UITextView throws EXC_BAD_ACCESS

I've created a UITextView instance and I'm trying to set its font:
UITextView *dummy = [[UITextView alloc] initWithFrame:self.frame];
dummy.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:14];//self.font;
However, at that second line, I'm getting EXC_BAD_ACCESS error, hitting continue execution doesn't do anything. It still hangs at the same line forever, with no error message at the console. It also used to throw at self.font too (I'm using the code inside a working UILabel and its font is a valid font object). Why am I getting this error?
UPDATE: I've also tried setText: it also throws the same too. Am I missing something obvious?
Try this code.
UITextView *textview =[[UITextView alloc]init];
textview.frame=CGRectMake(200, 10, 500, 50);
//To make the border look very close to a UITextField
[textview.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[textview.layer setBorderWidth:2.0];
textview.delegate=self;
//The rounded corner part, where you specify your view's corner radius:
textview.layer.cornerRadius = 5;
textview.clipsToBounds = YES;
[textview setFont:[UIFont fontWithName:#"Helvetica Neue" size:11]];
[textview setTextColor:[UIColor blueColor]];
[textview setReturnKeyType:UIReturnKeyDone];
I've found the solution.
I've tried [[UITextView alloc] initWithFrame:self.frame textContainer:nil]; instead of [[UITextView alloc] initWithFrame:self.frame]; and it worked. I don't understand why the other method didn't work, and this one works even though I'm using nil as the textContainer.

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
}

UITextView not loading/showing the large text?

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;

Resources