How do I achieve a clearly rendered rotated UILabel? - ios

I am trying to display rotated text. The UILabel is added as a subview on a UIImageView. The UIImageView has a transform created via say CGAffineTransformMakeRotation(M_PI/4.0). The text of the UILabel renders fairly blurry cf. the title label (in the screenshot, the blue background 'What's ...').
Do you know how I can manage to make the rotated text render clearly?
I've already tried using an integral-based frame (which matters little since it'll be rotated), a non-clear background color, and setting the label to opaque=YES. Still blurry.
Thanks!

The problem is that your label is rendered in half pixel either in the origin of the frame or the rotation. Check the frame origin after rotation, or try to rotate it by M_PI/4.1 (4.2, 4.3, 4.4, 4.5 - even test values like 4.05 4.15..) until it renders normally. Also check the frame of the UILabel in the UIImageView, could be added at half pixel origin for ex. {0.5, 0.5} or something..

Related

How can I use UIImageView with aspectFill and alignment to the top?

How could I use UIImageView with aspectFill and alignment to the top? Auto-layout or programmatically don't mind.
It can be done, but you are talking about quite a bit of coding. Let's start with a detailed description of what you are asking for.
We'll start with an iPhone6s in portrait mode with a screen size of 667x375 points, or a regular height by compressed width in size classes.
(Keep in mind, on any iPad you'll also need to work with slide-over and split screen too.)
But for now we'll go with 667x375. Into that we'll add our imageView as a square size of 375x375. Along the top of the screen when in portrait mode.
(Keep in mind that with AutoLayout you'll also have it pinned, and without putting some code in to determine if it's in landscape or portrait, otherwise, that 375x375 will shrink in landscape if you have other views underneath it.)
So now, stripped out to the most minimum (for now), we are talking about how to pin "an image" to the top of a UIImageView that is 375x375 in size and with a contentMode of aspectFill.
We need to find the size of the image next, based on both the largest dimension (height or width) AND how that dimension compares to the size of the imageView, calculate how the imageView will normally render it. The key figure you want is the height it will render it as
For instance, how will a 480x1020 (HxW) image fit into it? The 1020 width will be taken down to 375, so the height will be 480/(1020375) or 176.4705 points.
Always do the math for both dimensions - if your imageView isn't square or if the height isn't the "bounded" dimension, you'll be off.
Once you've calculated what the "Aspect Filled" height will be, check it against the dimensions of the imageView, and adjust the height of it as needed.
Here's where the real work comes in. If you are using AutoLayout, you can do a heightAnchor adjustment, but depending on how you pinned those other views things may be laid out really bad after you do. If you are using frames and CGRects be aware that you have to take into account iPad slide-out and split screen, etc.
Finally, if you want your app to load a different image in that imageView after it was loaded, you will have to "reset" the height back to what it originally was, at least in your calculations.
My recommendation is to find an alternative to what you are asking. For instance, put a small border around the image view to let the user know the true dimensions of that view.

UIImageView remove white area after rotation applied

I have a problem with rotating UIImageView. As you look at the attached screenshot you will find that image is rotated but the frame of UIImageView has some unwanted empty area. The blue line around image is the frame of UIImageView.
How can I remove that empty area? And assign that much of frame which is require by image.

UIScrollView according to background

I've an UIScrollView and I want to update his size according to his UIImageView background to exactly stay in the paper.
That the constraints I've added.
In othe size the result is wrong for example iphone 6s plus:
(It's fine in iPhone4s obviously)
I am assuming the picture with the rubber, marker, pencil and the stack of paper is a single UIImageView, and that the UIScrollView is on top of those.
If that is the case, you will have a very hard time to do what you are trying to, as you will have dynamically no idea how the stack of paper will be resized.
My solution would be to isolate each part of your drawing (the rubber, the marker, the pencil and the paper stack) in separate UIImageViews, then add the scrollView as a subview of the paper stack view: see this picture.
From there, add constraints to resize the scrollview dynamically according to its superview.
If you used full image, you have to use multiplier, not constant.
To do it, you need to calculate the position rate and use it for multiplier.
I've attached some images for example. It will be helpful for your project.
Only need to get the position rate and size rate of the object in origin image.
Setting multiplier for equal width with super view
Setting multiplier for Align center X with super view
Result in iPhone 4s
Result in iPhone 6

iOS Image Resizing / Dealing With Blank Space

I have simply dragged UIImageView into storyboard and made it square. I added a pink background to show the effects of the leftover space in the ImageView. In each case I added either a taller image (1st image) and a wider image (2nd image), as well as a text label. Here are my results.
So the obvious question is....how can I get rid of this extra (pink) space and keep the integrity of the photo (that is, to not have to stretch or lose part of the image)? If I wanted to be able to scroll through photos, it would be nice to have them all the same width to the edge so they look neat and orderly (if they were portrait), and if I wanted to have text under each, I'd want the text to be closer to it, rather than have all the blank (pink) space in between if it were landscape. And obviously different size images will give different sizes of blank space.
So I'm thinking what I could do is before displaying the image, get the size of it, then just have a designated distance from either the label or the edge of screen, depending on the orientation of the picture, and then creating/changing the size of the UIImageView with a bit of math and using the image dimensions before inserting the picture into the ImageView. Is this possible? Is there another method I can't quite figure out?
Just look at any decent photo app and they are nice and neatly organized/displayed despite being different sizes, orientations, etc and I'm wondering how to pull this off. I obviously haven't gotten too deep into using images past simply showing them in a pre-determined ImageView.
Thanks for the help/suggestions!
Try this... set your UIImageView to AspectFit (not AspectFill since that will lose some of the image) and using constraints do the following:
centre the UIImageView in the container both horizontally and vertically
set the UILabel to float below the UIImageView by whatever distance you desire ("standard" is usually good)
set the left, right, and top constraints on the UIImageView to be >= whatever distance you desire
set the bottom constraint on the UILabel to be (once again) >= whatever distance you desire
The effect of this should be that the UIImageView will properly resize itself to its intrinsic size and the constraints should properly position it and the label.

is it possible not to change an UIImageView frame when rotating an UIImage?

I got a quick question;
I've got an UIImage inside an UIImageView that I rotate (only the image).
As you know the frame will scale up so everything fits. Is it possible to ignore this behavior?
I just want to keep the frames where they, it doesn't matter if the corners are outside the frame.
Thanks :)

Resources