The above is what I get on the simulator regardless of the frame I set for the UITextView. The above UITextView is a subview to UIScrollView (the light gray view behind). And this UIScrollView has been presented modally. No matter what frame I set for the UITextView, its height remains as shown above. What could be the problem?
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 540, 620)];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 520, 80)];
textView.contentInset = UIEdgeInsetsZero;
textView.layer.borderWidth = 1.0f;
textView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:textView];
Thanks!
Noted one more thing. Changing the width of the textview from say the above 520 to 220 does indeed result in a change of width and it shows. But no matter what the value of height is, the textview keeps displaying with the same height as in the above image.
your UITextView size is dependent on the Height and width of UIScrollView first increase the size of UIScrollView size than increase th eUITextView size.
I'm getting the same issue and when I try to po the frame height it give me:
property 'frame' not found on object of type 'UITextView *'
This is after installing the new ios6 dev kit... so maybe that's it...
Yup that's it. If you go to file inspector in your xib or storyboard and untick "use autolayout" then that will help.. But's it's screwed everything, so I'm just going to make the damned uitextview programatically!
Related
scrollView = [[UIScrollView alloc] initWithFrame:
[[UIScreen mainScreen] applicationFrame]];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(25, 100, 200, 250)];
textView .text =#"long text ";
I will be getting some data of unknown length. to be added to the UITextView . Sometimes the height of the content of the text might exceed the height of the UITextView which is 250 (shown above).
How can i increase the height of the UITextView based on the text i receive ? I would appreciate a sample code? Later i need to add this to a UIScrollView (i know how to add to a scrollview), but again i don't know how to increase the height of the scrollview. Can someone help me code this ?
note: according to my code i am defining the width and height of the UITextView before adding the text to it.
UITextView is a subclass of UIScrollView. When the text content grows larger than the frame of the text view, the content will automatically begin to scroll. There is no need to embed a UITextView in a UIScrollView because it already is one (and more!).
Set the size of textView equal to it's contentSize.
The scrollView you have to set it's contentSize equal to the size you want.
I've got a very stubborn UIToolbar, who refuses to change its height no matter how may different methods I try.
I've seen this question and it does not work for me
Is there a way to change the height of a UIToolbar?
It is a toolbar for my cameraOverlayView while taking a picture. here is what I've tried and has not worked:
-Adjusting its current frame's height
-Creating a new CGRect for its frame
-Subclassing UIToolbar and editing its drawRect function
- (void)drawRect:(CGRect)rect
{
//Create a rectangle for the toolbar
CGRect rectArea = CGRectMake(0, 0, 320, 70);
[self setFrame:rectArea];
}
Is there some property I'm unaware of which prevents a UIToolbar from adjusting its height?
Just Follow How to change the height of UIToolbar
I have some code that creates a table cell with a slider. It's pretty straightforward and it sizes well on the iPhone. I've anonymized it a bit here:
UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Foo"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
CGRect contentViewFrame = cell.contentView.frame;
CGRect sliderFrame = CGRectMake(10, 0, 280, contentViewFrame.size.height);
UISlider* slider = [[UISlider alloc] initWithFrame:sliderFrame];
UIImage* minimumImage = [UIImage imageNamed:#"min.png"];
UIImage* maximumImage = [UIImage imageNamed:#"max.png"];
slider.minimumValueImage = minimumImage;
slider.maximumValueImage = maximumImage;
slider.value = 0.5f;
[slider addTarget:self action:#selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:slider];
[slider release];
Of course, this is incorrectly sized for the iPad. So my first thought was to set the autoresizingMask property to UIViewAutoresizingFlexibleWidth. Problem solved, right? Nope. Now on the iPhone, the width of the slider-plus-images content is less than 280 and so it doesn't go right to the end -- it ends up about 20 pixels short.
On the iPad, the same thing -- the width of the UISlider automatically resizes to about 20 pixels short of the end of the cell.
Perhaps the auto resize flag is paying attention to the non-existent accessoryView of the cell? I tried setting it to nil explicitly, but I think it's nil by default, so nothing changed.
I'd like this cell's content to resize automatically to be the "full" width of the cell, regardless of device and orientation. Is there an easy way to do this?
It works exactly how you described. I am inclined to think it's iOS bug. On iPAD when you create new UITableViewCell its width set for 320. hardcoded(!) both view and contentView. It does not resize properly if set to UIViewAutoresizingFlexibleWidth. I had it set to view.frame.size.width/2 with funny results: on iPhone it's 160, on iPad it's 608!!!
I ended up manually resizing my cells and their content.
Bit late but i found the solution of the same question today, but you need to create a custom UITableViewCell.
Then you can overwrite the function
- (void) layoutSubviews
{
[dateLabel setFrame:CGRectMake(10.f, 16.f, 80.f, 12.f)];
[textLabel setFrame:CGRectMake(106.f, 16.f, contentView.frame.size.width-105.f + 1.f, 12.f)];
}
In that function the self.frame.size.width is the actual one.
And it works with rotation of the device, too.
You should be able to tell the resizing system to "stick" the object a fixed distance from the right edge (where it's not resizing far enough). If you experiment with IB you can create a view that resizes in width and is fixed to the right side.
Do you have UIViewAutoresizingFlexibleRightMargin set as well?
Set your cell's contentMode to UIViewContentModeRedraw.
I've got a scroll view, in which I have an imageview displaying a 960x960 image, but it scrolls to something close to 4x that. I've tried to log the widths of all possible views and everything claims that it's 960x960 (or smaller, I think I logged the screen width once...?)
I need this image to stop scrolling at the bottom right corner of the image rather than entering deadspace. Any help would be greatly appreciated.
Heck, even telling me what the name of the object is that is larger than my scrollView.contentSize would put me on the right track...
//Test-Image is just a 960 by 960 image that's numbered around the edges 1-10 so you can tell if it's being moved
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Test-Image.png"]];
self.imageView = tempImageView;
[tempImageView release];
scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
//Tested with this, results the same.
//[scrollView setContentSize:CGSizeMake(960, 960)];
NSLog(#"What is my scrollView's height attribute?...%f", scrollView.contentSize.height);
// Returns 960
NSLog(#"What is in scrollView's width attribute?...%f", scrollView.contentSize.width);
// Returns 960
scrollView.contentOffset = CGPointMake(480, 480);
scrollView.maximumZoomScale = 8.0;
scrollView.minimumZoomScale = 0.25;
// Commenting clipsToBounds out doesn't seem to have any effect
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
Unfortunately, I do not have a specific answer.
Reference. Try [scrollView addSubview: self.imageView]; instead of [...addSubview: imageView];
Content Size. Try setting the content size after adding the ImageView.
[scrollView setContentSize: CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
Delegate. Did you use and set the scrollview's delegate property (oIWScroll.delegate = self;)?
Clipping. It should not matter.
ScrollView Frame. Make sure the frame of the scrollview is equal to or smaller than [UIScreen mainScreen].applicationFrame.
Framing. When I had a situation similar to what you described, one of the the things I did was to create a container UIView, add it to the scroll view and stuff the objects into the container view. But you really should not have to do that for one image.
I also set the contentMode = UIViewContentModeTop.
I hope these suggestions help.
I already did several searches on Stack Overflow and Google, but I couldn't find a solution to my problem.
I have a Detail View for a product that includes a UIScrollView and a few subviews (UIImageView, UILabel, UITextView). You can find an example here.
First I wanna autoresize the UITextView (not the text itself!) to the corresponding height. Then I wanna autoresize the entire UIScrollView so that it fits the height of my UITextView and the elements above it. I've tried the following code:
myUITextView.frame = CGRectMake(2.0, 98.0, 316.0, self.view.bounds.size.height);
[scrollView setContentOffset:CGPointMake(0.0, 0.0) animated:NO];
scrollView.contentSize = CGSizeMake(320.0, 98.0 + [myUITextView frame].size.height);
[self.view addSubview:scrollView];
98.0 + [myUITextView frame].size.height) because my thought was: After getting the height of myUITextView, add the height of the other subviews (98.0) to it.
Unfortunately it doesn't work very well. Depending on the content of the UIScrollView, it is too short or too long. I did some logging with the result that the height of the UITextView is always the same:
2010-01-27 14:15:45.096 myApp[1362:207] [myUITextView frame].size.height: 367.000000
Thanks!
There is actually a very easy way to do resize the UITextView to its correct height using its contentSize.
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;
One thing to note is that the correct contentSize is only available after the UITextView has been added to the view with addSubview. Prior to that it is equal to frame.size
A UITextView won't automatically resize itself to it's contents (not as far as I know anyway) so you need to get the size of the text yourself and size the UIView accordingly.
The functions on this page will help - you can use them to get the width and height of a string, something like
// Get the size that the string will render at
NSString *contents = #"This is the content of your UITextView";
CGSize areaSize = [contents sizeWithFont:myView.font forWidth:myView.frame.size.width lineBreakMode:UILineBreakModeWordWrap];
// Then set the frame of your UITextView to be the right size
myView.bounds = CGRectMake(0, 0, areaSize.width, areaSize.height);
Then, you can layout the other components around it.
Hope this helps,
S
PS Warning, the link to the docs is correct but my code example is untested, sorry :)