tabbar and view sizes xcode - ios

I have a simple app with a tabbar. The view size is 480 x 320. The tabbar is 49 x 320. However when i try to take a screenshot using UIgraphicsbeginimagecontext(self.view.frame.size) I get an image of 411 x 320..
My background image is 480 x 320 and shows properly in the ios simulator.
However when the screen is captured the background image is cut by the 69 height pixels.
Anyone knows:
1) Where the 20 missing pixels are going (480-49) = 431 while im getting 411
2) Why my background image displays properly in simulator but is cropped when taking a screenshot..
Many Thanks

Try using self.view.bounds for the context size.
Also, are you taking the screenshot before the view has been properly initialized? If you are, this may result in an incorrect size.

The missing 20 pixels are the size of the status bar on the top. Actually your view size height is 460 pixels if you are displaying a status bar on the top. When you take a screen shot using UIgraphicsbeginimagecontext(self.view.frame.size) your size parameter is 320x460, and NOT 320x480 as you expected, resulting in a "cropped" image. (sorry about my english...)

Related

iOS how to handle image upscaling,downscaling,image stretching and other issues

I have an image which is completely red but there is a small line which is white in color and mid of the screen.But the line disappears as its getting downscaled I believe.
so if I my imageview width is 20 by 20.my 1x image should be 20* 20 and my 2x image should be 40 by 40 and my 3x image should be 60 by 60.
if I want to vector way then I can use pdf images which is of 20 by 20 and keep it 1x and it will be get scaled up to 40 for 2x and 60 for 3x.
Please correct me if I am wrong.
When I try to show image on bigger imageview of width and height as 300 by 200 then sometimes image gets stretched. how can I avoid that ? Have to maintain the image aspect ratio width and height w.r.t imageview.
I have heard using aspect fit content mode can solve the image stretch issue.
somebody please clarify me as other answers in stack overflow leads to bit more confusion.
Cheers

How to work with Ipad images? Xcode

I am creating an Ipad app and no matter what height I set my ImageView to be it is always too big.
For example I have an ImageView that's about 20 pixels tall and has all of the constraints that I need to keep it where I want it to be. When I play this 20 pixel tall ImageView on the Ipad simulator the ImageView covers about half of the Ipad screen.
How can I work with Ipad images if even a 1x1 pixel image view takes up a signifiant amount of the screen? (Yes, I made the 1x1 image just to see if it would still be insanely large)
Under Auto Layout, if you don't set the size of the image view absolutely, it will size itself to match the size of the image assigned to it. That is probably what is happening to you.

How to set a width constraint on a UIButton

I have a button that I want to be a constant size across all devices (iPhone 4,5,6, iPad...etc). I want that button to be 347 x 66 pixels wide. I currently have the following constraints:
However, the width constraint isn't followed. This is what it looks like when ran in simulation:
Any ideas on how to get it to always be 374 pixels wide on any device ?
Thanks
You should always design in points not pixels, which is why constraints are in points. The iPhones up to the 5s are all 320 points across in portrait mode, so 374 points would be wider than the screen. The two iPhone 6 models are a bit wider, in points. The simulator image you posted is indeed trying to show a button which is 374 points wide, i.e. wider than the screen. Perhaps you intended to make a button which is half that width, 187 points, which is 374 pixels on a 2x retina screen?

Using CGRECTMAKE what is the ratio to convert an iPhone 4 ..rect to an iphone 4s rect Xcode

I have used CGRECTMAKE to position an image onto the 'camera' screen and was wondering whether there is a calculation ratio to convert a 4 image placement to a 4s
Iphone 4 screen is 320 480
iphone 4s screen is 640 960
I have tried just doubling my values but that doesnt seem to work so thought someone may know a formula to convert them
I cannot use AUTOLAYOUT or PLACE IMAGES ON SCREEN in storyboard as i am placing an image onto the camera screen..have tried these but no joy
thanks in advance
Not sure if I get your question correct but CGrectMake utilizes points, not pixels. Since the screen on i4 has the same size as the screen on i4s, There should be no implementation differences.
You should use 320*480 measures. The screen is devided into 320*480 points for i4/i4s

problems with Screenshot size in application with tabbar

I have a simple app with a tabbar. The view size is 480 x 320. The tabbar is 49 x 320. However when i try to take a screenshot using UIgraphicsbeginimagecontext(self.view.frame.size) I get an image of 411 x 320..
My background image is 480 x 320 and shows properly in the ios simulator.
When I use UIgraphicsbeginimagecontext(480x320) I get empty space in the bottom of the screenshot..
However when the screen is captured the background image is cut by the 69 height pixels.
Anyone knows why my background image displays properly in simulator but is cropped when taking a screenshot.. Or how to capture all the screenshot if I increase the imagecontext size?
Many Thanks
Is the status bar showing? It sounds like the status bar (20px) and the UITabBar (49px) is where the extra space is being cropped. I imagine that self.view is returning a UIViewControllers view which is smaller than the shot you want.
If you want just the background image, try reducing the size of the screen shot, or if you want the whole screen, try targeting the apps main window, something like this
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Resources