I have a UIScrollView inside my UITableViewCell. I have a NSAttributeString inside this displayed (I am using this framework. Basically what I want to do is to adjust the size of the cells and the UIScrollView as well.
If the text in the NSAttributeString can fit in a UIScrollView less than 500, then the UIScrollView gets that height. Otherwise let the UIScrollView height's be 500.
Now the problem is that it gets more complicated than that. The NSAttributeString is an HTML and so it's hard to estimate the height of the row just by treating the HTML as strings as it can have image etc. So is there a way to go around this, so I can set the height of each row dynamically according to the content of the UIScrollView...
I was also looking for this kind of thing. Someone suggests me to get height using UIWebView when page loads get heigh by some javascript. Here is the original question
How to calculate height of html string?
Related
I am using Core Text (for text bleed/wrap effect). Since the body of the UIView has to grow with the text and images put onto the view, I want my UIView to adjust its height accordingly.
I tried sizeToFit (on my UIView) to adjust its height according to its contents. However, the UIView doesn't increase its height, although it can decrease it alright.
This is how my hierarchy of the UIView looks like:
[UITextView]
[UIImageView] (can be 0 or many)
How could I make my UIView adjust its height according to the contents it has?
I am putting the text in a UITextView and then displaying it in the UIView (using CoreText), so I basically set the height of my UIView as:
(height of textview) + (height of images)
Although it isn't an elegant solution but atleast it works alright.
PS: a better solution might be to add a right proportion of height and width (since the text wraps around the image).
Setup: I have a UIView with a scroll view nested within it. Within the scroll view I have a label, uiimage, and a tableview (grouped). The label, uiimage, and tableveiw are populated by a webservice. The last section in the grouped table view contains text that will never be the same and could be as long as 5 characters to 250+. Also, this view is pushed from a basic tableview (so it has a navigation bar. If that matters at all).
Expected: The uiview should extend in height depending on the height tableview extends to. Then I will be able to set the scrollview to accommodate the height I need to be able to scroll.
Problem: I'm not quite sure how to approach the issue. I really only know how to change the height to fixed values, which will not work properly in almost any scenario.
Am I using UIScrollView incorrectly? Do I need to resize the UIView at all?
You don't have to modify your UIView frame size, which has to be the size of your screen. The UIScrollView frame size must also be the same, it represents the part of its view actually displayed.
What must change is the UIScrollView contentSize, which defines height and width for data inside it ;)
You can calculate it using each inside element's height and by adding the correct margin.
Thus, you could have a UIScrollView content size of 320 * 600, which will let you automatically scroll down.
In fact, you have to display your content independently of the final frame size. If you have a content of 500*500, just display it inside your UIScrollView. Then tell it the size of it's content, and it will automatically set scrolling possibilities if needed.
Turns out I had to create a UIView programmatically and set it as the header of the UITableView. It works perfectly now. :)
I have DetailView in which there are three textviews which are showing different informations. is it possible that on whenever i scroll down to read all information. all those textviews scroll like they are one page. i mean they look like one textview. i m doing this bcz i need those information in different fonts. and if there is any other nice approach i can use to show that information? plz tell me.
thanx in advance.
Yes, you can place those three UITextViews into a UIScrollView, set userInteractionEnabled = NO in the UITextViews, and properly set the contentSize of the UIScrollView to cover all 3 UITextField size, then they will all scroll as one unit and the UITextViews won't scroll at all within themselves. (Again: a UIScrollView will not scroll in height / width unless the contentSize property's height / width is larger than its frame property height / width).
I have a few UILabels in my view with their height set using sizeWithFont:.
I set the autoreszingMask to flexible width and height, however on rotate the width changes (am assuming because self.view's width changes and its set with a width relative to self.view) but the height of it doesn't change to fit the content again. This results in a large white space at the top and bottom.
Just wondering how I would go about re-sizing the UILabel on rotation? Is there any automatic way of doing this, or is there a way of getting all UILabels and re-doing sizeWithFont when the device is rotated?
The UILabels are subviews of UIView heirarchies used as headers for sections in my UITableView.
Thanks
Tom
You should really send sizeToFit to any UIView, especially UILabel, instead of forcing some arbitrary size on them.
The best approach is usually to first set the maximum width and current height, then send sizeToFit, then adjust the width again if necessary. In case of multiline labels it looks like the most foolproof way to avoid layout bugs.
The problem was having a flexible left and right margin on a slightly offset uilabel.
If the label isn't centered then you need to choose left or right and set the flexible margin for one of those.
This seems like it should be simple but I can't work out how to do it.
I've created a UITextView in interface builder. It doesn't sit in a table cell or anything fancy like that.
What I'd like to do is have the UITextView scroll itself to the left when the user has typed their way all the way to the right margin.
At the moment it just does a word wrap, I understand the word wrap makes sense in most situations but I need it to scroll instead. What I'm after is the same behavior it exhibits vertically.
I've tried adjusting the content size of the UITextView in viewDidLoad and also in viewDidAppear and that doesn't make a difference.
I've also played with the inset settings in IB but that doesn't affect the scrollable size, just WHERE it's displayed.
Does anyone have any ideas?
If you only need a single line of text that scrolls, you would probably be better served by a UITextField. UITextViews are meant for multi-line text input, which is why word wrap is the default. You can't, as far as I know, override that behavior.
Ok, it doesn't look like it can be done exactly how I wanted but I've come up with a hack to get me there.
Let's say I want a scrollable width of 600 and a visible width of 250.
The first step is to make the UITextView a wide as the area you want to be scrollable. So what you would have put into contentSize, in this case 600.
Then the right inset is set to the difference between the actual width and the width you wanted. In this case 350.
This way cursor is restrained to the width you need BUT there is text visible to the right of your desired width, after all, the UITextView IS 600 pixels wide.
Now here's where the really hackish bit comes in, don't read on if you're sensitive or have a weak stomach.
Get an image of the user interface to the right where UITextView should end. Insert it into the NIB as an UIImage view and put it back in it's place, making sure that it's on top of the UITextView.
When the view is displayed, the cutout sits on top of the UITextView and hides the text overrun.
I'm not proud, but it works.