I have a UITableViewController with a UIView before the table view. The UIView (IBOutlet UIView *templateDescriptionView) has a UITextView (IBOutlet UITextView *templateDescription) in it. It looks like this:
The UITextView can have a variable amount of text. I'm trying to programmatically resize the UITextView and UIView to compensate for this, but it's not working as expected.
-(void) viewDidLoad
{
[templateDescription sizeToFit];
CGRect frame = templateDescription.frame;
frame.size.height = templateDescription.contentSize.height;
templateDescription.frame = frame;
CGRect viewFrame = templateDescriptionView.frame;
viewFrame.size.height = templateDescription.contentSize.height + 40; // 40 for padding
templateDescriptionView.frame = viewFrame;
}
The problem is, when everything renders, the UIView is partially on top of the UITableView. It resizes, but it's not resizing to the proper height. What am I doing wrong? This is Xcode 5, iOS7.
I am afraid I misunderstood your meaning. But UITableViewController is used to control a UITableView. Does it run well that a UITableViewController control a UIView? Maybe you put a UIView into the HeaderInSection of tableView. In iOS7, self.automaticallyAdjustsScrollViewInsets = NO; can be used to remove the space inset in scrollview.
Related
I have the following code in viewDidLoad on my ViewController:
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:204.0/255 green:00.0/255 blue:00.0/255 alpha:1];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
autoNameLabel.text = (NSString *)[vendorDetails objectForKey:#"autoname"];
homeLabel.text = (NSString *)[vendorDetails objectForKey:#"homelab"];
descriptionTextView.text = (NSString *)[vendorDetails objectForKey:#"description"];
This all fits perfectly on the view. I know need to add an additional textView on the bottom so need the user to be able to scroll to see it. How can I add this info to a scrollable view and add my additional textView?
you could have your UIViewController extend UISCrollViewController. Or you could add a UIScrollView to your view controller's view in the method viewDidLoad. Then add all subviews of your view to the scrollview instead.
self.scrollView = [[UIScrollView all] initWithFrame:self.view.bounds]
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.width, HEIGHT_OF_SCROLLABLE_AREA).
I would also do something like this for the scroll view height if your last textview is named lastTextView
HEIGHT_OF_SCROLLABLE_AREA = CGRectGetMaxY(lastTextView.frame + bottomPadding)
Are you sure you dragged all the other views on the scrollview? Make sure the contentSize of the scrollview is high enough(you know, higher than the screen) to scroll.
have u set delegate of UIScrollView. if you have not set delegate of UIScrollView then also it may possible that your scroll is not working.
Using storyboard i want to add UITextview in the UIScrollview and the scroll the TextView in the in the screen. please help me...
scroller.contentSize=CGSizeMake(320,846);
[scroller setScrollEnabled:YES];
int GetIndex = [GetSelectedIndex intValue];
label = [firstheading objectAtIndex:GetIndex];
labelheading.text=label;
textviews = [firstdesc objectAtIndex:GetIndex];
textview.text=textviews;
[scroller addSubview:textview];
NSLog(#"textview:%#",textview);
NSLog(#"image:%#",getimage);
Just a suggestion, you could try adding a UIView on your ViewController first.
Then drag the UIScrollView into your UIView.
Then drag a UITextView into that.
I have this arrangement in a Storyboard - because I have an image in the top level UIView as well as the UIScrollView
I need a dynamically resizing UITextView but the right margin encroaches towards the left alarmingly after numerous resizes so that a very narrow strip of text is shown with lots of white space in the text view. This can be reproduced by a simple setup with just a UITextView and UISlider. A simple sample setup that produces this behavior is UISlider with value range from 0-200, a UITextView of 320 width and this code:
- (IBAction)sliderValueChanged:(UISlider *)slider {
textView.frame = CGRectMake(0, 0, 320 - slider.value, 300);
}
Some things I've tried are tinkering with the autoResizingMask, contentMode, contentOffset, and sizeToFit but none of them work. How can this weird behavior be avoided, or is it a bug?
Subclass UITextView and override layoutSubViews to set the frame to CGRectZero and then back to original frame size. It's not elegant but it works.
-(void) layoutSubviews
{
CGRect rect = [self frame];
[self setFrame:CGRectZero];
[self setFrame:rect];
}
I'm trying to insert a TextView inside a Scrollview. The scrollview work but the content of TextView not show complete, because appear their scroll. I would show complete content of TextView without scroll.
file.h
#interface DetailViewController : UIViewController{
IBOutlet UITextView *detailTextView;
IBOutlet UIScrollView *scroller;
}
#property(retain, nonatomic) IBOutlet UIScrollView *scroller;
-(void)setTextViewForRecipes: (Recipe *)theRecipe;
#end
file.m
#implementation DetailViewController
#synthesize scroller;
-(void) setTextViewForRecipe:(Recipe *)theRecipe
{
[detailTextView setText:theRecipe.detail];
}
- (void)viewDidLoad {
CGRect frame = detailTextView.frame;
frame.size.height = detailTextView.contentSize.height;
detailTextView.frame = frame;
[scroller setContentSize: CGSizeMake(280, detailTextView.frame.origin.y + detailTextView.frame.size.height + 10)];
}
You've got the right idea in viewDidLoad by setting detailTextView's frame height to its contentSize height. But you need do that after you set the text of the view, and of course you need to adjust the scroller's contentSize again.
-(void) setTextViewForRecipe:(Recipe *)theRecipe
{
detailTextView.text = theRecipe.detail;
CGRect frame = detailTextView.frame;
frame.size.height = detailTextView.contentSize.height;
detailTextView.frame = frame;
scroller.contentSize = CGSizeMake(280, 10 + CGRectGetMaxY(frame));
}
UITextView is a subclass of UIScrollView, so you shouldn't add it to a scroll view.
As bandejapaisa pointed out, it's usually not necessary to wrap a UITextView inside a UIScrollView, because the textView can scroll by itself.
If, however, you really find this necessary, you can find out the size of the text if it were rendered with a certain font:
CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:fontSizeOfYourTextView]
constrainedToSize:CGSizeMake(widthOfYourTextView, MAXFLOAT)
lineBreakMode:UILineBreakModeOfYourTextView];
This will find out the height. Adapt to your needs, but be warned: This gets a little hackery, and you'll probably need to do some trial and error before you achieve the desired outcome.
I have UIScroll that have uitextview inside it.
My apps look like this:
rootviewcontroller -> PhoneContentController (UIScrollView and PageControl) -> DetailController (UITextView, UIWebView, UILabel).
My Flow is like this:
Set UIScrollView default size -> call DetailController (calculate UITextView and other page inside it in viewDidLoad) -> PhoneContentController get the total height size from DetailController-> Change the height of UIScrollView
This is the code in PhoneContentController (loadSCrollViewWithPage):
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, [detailController.getTotalHeight]);
The code in Detail Controller (viewDidLoad):
summaryBlogParsed = [summaryBlogParsed stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[self.itemSummaryText setText:summaryBlogParsed];
CGRect frameTextView = self.itemSummaryText.frame;
frameTextView.size.height = self.itemSummaryText.contentSize.height;
self.itemSummaryText.frame = frameTextView;
This code in DetailController getTotalHeight:
CGRect cgRect = [[UIScreen mainScreen] bounds];
CGFloat scrollFrame = (cgRect.size.height/2) + itemSummaryText.frame.size.height;
return scrollFrame;
I can scroll the scrollview but the textview not load all of the string. like only half of it, but i can scroll down but with blank pages :(.
Anyone can help me?
Thank you
set content size of scroll view using this function.
-(void)setContentSizeOfScrollView:(UIScrollView*)scroll
{
CGRect rect = CGRectZero;
for(UIView * vv in [scroll subviews])
{
rect = CGRectUnion(rect, vv.frame);
}
[scroll setContentSize:CGSizeMake(rect.size.width, rect.size.height)];
}
after adding all controls to your scroll view call this function and pass yourScrollView as argument. Hope this will help you.........
According to Apple... When debugging issues with text views, watch for this common pitfall:
Placing a text view inside of a scroll view. Text views handle their own scrolling. You should not embed text view objects in scroll views. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.