UIWebView not scaling to UICollectionViewCell - ios

I'm trying to implement a UICollectionView that contains UIWebviews in each cell. I've almost got it working but I am having this problem of not being able to resize the webviews to the cell's content size. Each webview size so far is 1024x704 (width x height) and is a html file. I have enabled scalesPageToFit to YES but all it's doing right now is resizing it to only fit in the upper left corner.
I've checked the frame size of the webview and the collectionviewcell size and i get 1024x704 programmatically even though what is actually appearing seems to be a lot smaller than that.
Any suggestions/help on why this is happening and what I can do to scale it correctly? If I need to supply more info let me know. Thanks
EDIT:
As shown below this is how the UICollectionView looks like on an iPad. The rectangle in the left is the UIWebView and I'm trying to scale it to fit the whole screen.
EDIT2: Just realized I screwed up on how I wrote my html file. Sorry about that guys! Problem solved itself.

Try this:
self.webView=[[UIWebView alloc]initWithFrame:self.bounds];
self.webView.contentMode=UIViewContentModeScaleAspectFit;
self.webView.scalesPageToFit=YES;
self.webView.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

Related

Detail Text and Accessory Don't show [duplicate]

I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.

UIScrollView zooming only to the size of UIImageView

I have UIScrollView in which UIImageView is held like on the screenshot:
My problem appears when I zoom and instead of being able to scroll only in the area of my image (subview of scroll view) I'm able to scroll around the original size so I get a lot of white space around my image which isn't what I want. You can see what happens on the screenshot below:
I wonder what should I update to keep my scrolling area only the size of the image?
After some research, some trials and errors I've finally achieved what I was planning to do.
First of all, I wanted to use only autolayout with IB which sure can be done but with some effort. After some digging I've found this technical note which by "Pure Auto Layout Approach" understands adding contraints in code but I was aiming at only IB which led me to this simple but beautiful solution called ios-imagescroll. After investigating this code with joy that I've finally found solution I came with some error but only on iOS 8 devices... iOS 7 worked like charm out of the box.
I assume that due to big changes in iOS 8 autolayout is more strict and you must be 100% sure what you want to accomplish. It turned out that this slight change MATTERS on iOS 8:
Of course, this bug, fix (call it whatever you like) was fixed by experimenting with everything but I guess that UIScrollView's content view (in that case UIImageView) must be the first item in constraint.
[yourScrollView setContentSize:CGSizeMake(yourScrollView.size.width, yourImage.frame.origin.y + yourImage.frame.size.height+35 )]; //let's say just 35 ...
yourImage may have x,y origins like (0,0) [I see a lot of space above it, so I assume you have set other values for x,y]

Resize webview iphone 5

i'm seeking a method to resize my webview according the current iPhone.
I tried to change the frame of the webview, to check the autolayout etc. but it's not running, I tried other solutions, and i didn't succeed to resize my webview.
I tried for example this but nothing change :
_contenuNews.frame = self.view.frame;
I don't want to use
Scale page to fit.
I want my webview take all the screen.
Someone to help me ? Thx
If your webview is added via IB and if you are using autolayout then you can not resize the frame. For this you need to uncheck the autolayout option from IB.
After that try to resize the frame of your WebView.
Though you didn't want to use scale to fit but it will be good to use scale to fit. It may help other so I am adding it to my answer:
self.webView.scalesPageToFit =YES;
The above code will make sure that the content of UIWebView is loaded inside the view frame.
Hope this helps.. :)

PDF in UIWebView: Initial view to fill view

I have a UIWebView that displays a PDF. By default it opens the PDF and scales it to fit the entire width in the view, but not the height. I want it to fill the view so that the height stretches down to the bottom.
I have tried using contentModeScaleToFill, zoomToRect, and any other thing that sounded like it might have any relevance.
Can anybody help with this?
You might want to try #Jeff's suggestion and use CGAffineTransformScale to rescale your pdf after it is loaded to fill the screen. Look at his answer here: https://stackoverflow.com/a/3600665/188675
And to answer your question, 1) contentModeScaleToFill is a UIView Constant so it won't help with anything in your case, because you're using a UIWebView. 2) Using CFAffineTransformScale is much more simple and straightforward than using zoomToRect because you don't have to mess with the scrollView.

UIScrollView not working

I have a UIScrollView with a View inside of it. Inside of that view is a bunch of buttons, labels, etc that fit in the View when in Portrait mode...When the iPad is rotated, I want the scrollView to kick in so the user can scroll to the bottom of the view. The app runs, but when I rotate it, the scroller never works...I believe I've wired everything up correctly and I have this code in the viewDidLoad event:
[scrollview addSubview: masterView];
scrollView.contentSize = [masterView sizeThatFits:CGSizeZero];
Is there something else I am missing? Do I need to modify the size when the iPad rotates?
thanks
There may be a problem with the content size of the UIScrollView. Without the contentSize being set larger than the actual scrollView size, scroll bars won't be shown.
You can code this in with something like this:
[scrollView setContentSize:CGSizeMake(2000,2000)];
And then changing the content size to the actual content size of what you are putting in the UIScrollView (scrollView).
If you look at the results of [masterView sizeThatFits:CGSizeZero] (e.g. NSLog or set a breakpoint in your debugger, I think you will find that it's not what you expected it to be. You might find that masterView has autoResize parameters set (which is common for a view that covers the entire screen), which means that it might, itself, be getting resized too short to fit all of its controls and scrollView is simply grabbing this shortened value itself. Take a look at that CGSize and the problem will be obvious.
I faced similar situation but my case was iPhone.
Remember that content should be larger than scroll for scrollView to kick in.
"Why would you want to go down if everything is visible in front of you ?"
use the following code:
[scrollView setContentSize:CGSizeMake(intValue, intValue)];
intValue: Integer values setting width and height of scroll.
Even if it doesn't works, don't worry there are loads of other options to figure out the solution:
1. NSLog
2. Breakpoints
3. Put up errors you are getting from console on stackoverflow

Resources