How To Fix UITextView in storyboard TextView - ios

Here i want to fix a UITextView which i created programatically in textView added on storyboard. I have tried it this way but not working.
_textView is a textView in which i have to fix UITextView *descrip
contentView is the view on which i have _textView.
UITextView *descrip = [[UITextView alloc]init];
descrip.view.frame = CGRectMake(_textView.frame.origin.x,_textView.frame.origin.y,_textView.frame.size.width,_textView.frame.size.height);
[self.contentView addSubview:descrip.view];

You can do something like this--
UITextView *descrip = [[UITextView alloc]initWithFrame:_textView.frame];
[self.contentView addSubview:descrip];
there is no need to to use CGRectMake if you want to give same frame as _textView frame.

here is proper method
UITextView *descrip = [[UITextView alloc]initWithframe:CGRectMake(_textView.frame.origin.x,_textView.frame.origin.y,_textView.frame.size.width,_textView.frame.size.height)]
[self.contentView addSubview:descrip];

If I understood correctly, you are trying to add descrip into_textView; try this:
UITextView *descrip =[[UITextView alloc]initWithFrame:CGRectMake(0, 0, _textView.frame.size.width, _textView.frame.size.height)];
descrip.backgroundColor=[UIColor blueColor];
[self.contentView addSubview:descrip]; //here add subview to texview not content view

Related

Custom View with dynamic Height as UITableView Header ios xcode

In my project,i have a 1.MovieplayerView,2.a label with dynamic content,3.a tableView with variable number of rows.
I was doing this with all these views in scrollView.But i always have the issue with dynamic height of the label.it sometime overlaps the tableView.
I came to know that we can use customView as the tableView header.How this can be done with variable content Height and autolayout?I am new to iOS.Any suggestion ??
I know how to add a view as the header to a table.But when the contents in the view changes,it overlaps the contents of the tableView.
I went through
How to resize superview to fit all subviews with autolayout?,How do I set the height of tableHeaderView (UITableView) with autolayout?
Can some one give a simple example on how to do this?Or tell me if it is better to use a scrollview and add all these views as its subviews? any suggestion would be realy helpful.Thanks.
In viewDidAppear,
1. Get the height of the dynamic content, then set the height of your tableHeaderView accordingly.
2. Set the headerView again so the table view can refresh:
self.tableView.tableHeaderView = headerView
Try using following code is this what u want to achieve can u clearify me please
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 40)];
NSString *string = [NSString stringWithFormat:#"/ %#",selectedCategory];
label.font = [UIFont fontWithName:#"Helvetica" size:15.0];
label.textColor = ThemeColor;
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:0.933f green:0.933f blue:0.933f alpha:1.00f]];
return view;
}
Don't forget to place this in nib of UITableView
It's hard to interpret your question regarding your use of the scroll view. If what you want is a custom view as the table view header, you could override this method in your table view class:
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section

How do you add a UILabel to a UIScrollView?

I'm trying to add a UILabel to a UIScrollView. I followed the steps in this tutorial. But for some reason, the label is not showing on the scrollView when I run the app. The app consists of a storyboard with two files (ViewController.h and ViewController.m). In the storyboard there's only one view controller which is a custom class of ViewController. Below is my code which is in the ViewDidLoad method of ViewController.m.
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, 250.0)];
testLabel.numberOfLines = 0;
[testLabel sizeToFit];
testLabel.text = #"test";
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 568.0)];
[scrollView addSubview:testLabel];
I tried the following lines of code at the end of my current, but still doesn't help.
[testLabel release];
[scrollView release];
You are calling [testLabel sizeToFit] before setting the text. This is setting the size of the label's frame to 0, 0.
Call sizeToFit after setting the text.
Make sure the view adds the scrollView as a subview too.
And a word to your fixes. Since Objective-C supports ARC (Automatic Reference Counting) the call "release" is not needed anymore.

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

Positioning UILabel inside a UITextView

Trying to position a UILabel above some text, but the elements are "stepping" on each other. I positioned them with x,y,h,w such that they should not do this but alas, they are. You can see in the screenshot that the label text "Abalone" and the text are commingled. What changes do I need to make here? I've already tried changing the x,y,w,h values to no great effect...
txtView = [[UITextView alloc] initWithFrame:CGRectMake(10,20,280,300)];
[txtView setFont:[UIFont fontWithName:#"ArialMT" size:14]];
txtView.text = word.definition;
txtView.editable = NO;
txtView.scrollEnabled = YES;
[txtView scrollRangeToVisible:NSMakeRange([txtView.text length], 0)];
txtView.minimumZoomScale = 1;
txtView.maximumZoomScale = 10;
UILabel *wordTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 20)];
wordTitle.text = word.term;
[txtView addSubview:wordTitle];
[detailsViewController.view addSubview:txtView];
I think the problem is you are adding the label view as a subview to UITextview. You have to reserve some space for the label view in the UITextview. You can either add some padding to the textView, which can be confusing, because padding in UITextView is not constant and varies based on the font size. Or you can add your UILabel directly to the detailsViewController.view and start your UITextView below the label.
Hope it helps.

ios uiview uiimageview uitextview

I have a main UIView that has an UIImageView on it, and the UIView adds an UITextView as a subview. UITextView's frame is smaller than UIView. UIImageView is actually a frame and the rest of the image is transparent and fits the full size of the UIView, but the UITextView is always upon UIView. What I want to achieve is UITextView shows UIView in foreground, while it is possible to scroll up and down on UITextView.
What is the proper way to make it possible?
My current code that does not work:
in loadView:
self.contentview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.contentview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"ChristmasFrame.png"]];
self.contentview.opaque = NO;
self.contentview.userInteractionEnabled = YES;
[self setView:self.contentview];
in viewDidLoad:
[self.contentview addSubview:self.textview];
[self.contentview sendSubviewToBack: self.textview];
I want UITextView to be behind self.contentview, so it could show its background image upon the UITextView.
try setting setUserInteractionEnabled: to NO on UIView what is on top of UITextView
if that not working you could try to override hitTest:withEvent:
make clear color as textview's background color.
and add text view above UIView

Resources