UILabel text getting compressed/stretched upon applying scale transform - ios

Am applying a scale transform to UIView (CGAffineTransformMakeScale) which contains UILabel as subview, as I apply transform, the label text gets stretched/compressed as shown in attachment, How can I make the UILabel to render the text correctly even after applying transform.

Apply the transform on the UIView and then add the UILabel as subview. The way you are doing will always transform the UIView and all his subviews. You can also change the UIView frame instead of applying a transform.

Related

detect subview's frame when superview transform

I have a UIview with some subviews in it! When I transform that view (scale, rotate.. use CATransform3D). These subviews grow bigger or smaller but the subviews do not change the frame. How can I detect the real frame of them? Thanks!
viewTransfromContainer?.layer.transform = CATransform3DScale((viewTransfromContainer?.layer.transform)!, pinchGes.scale, pinchGes.scale, pinchGes.scale)
I used convert(<#T##rect: CGRect##CGRect#>, to: <#T##UIView?#>) It's work fine with scale But Not return true value when rotate.
image bellow

How to achieve label embededd in UIImageView in iOS Swift like shown in image?

I want to achieve label/Button embededd in UIImageView in iOS Swift like shown in image.Has anyone done that?
You just need to play with UIView, UILabel And UIImageView.
You view hierarchy will be like below...
- UIView (mainView)
- UIImageView (imageView)
- UILabel
You need to make mainView.clipsToBounds = true so that after giving corner radius to it, it's subview will not go beyond its superview's bounds.
For imageView, you can set its content mode to aspect fill/ aspect fit as per your requirement.
Have a square UIView with clipsToBounds property set to YES which contains UIImageView and UILabel. The image view should cover all the view frame. The label should be positioned at the bottom of the view over the image view. Then just set appropriate corner radius (half of the view's height) for the view's layer and set its masksToBounds property to YES. That's it

is it possible to add uiview with big frame into uiview with small frame

In my app, I need to add subview in another view but my issue is that height and width of parentView is 50*50 and height of subview is 150*150 so how can I add this? because when I add this view, rest portion of subview is getting cropped.
The edges are bounded in the smaller UIView. Because the UIView is smaller it is going to crop out the larger subview. if you still want the super view to be 50x50 and don't want the larger subview cropped out then turn off setClipsToBound property of the UIView:
Swift: view.setClipsToBound = false
Objective-C: [view setClipsToBound:NO];
Another solution is just to make the subview smaller or make the superview containing the large subview larger.

Animate a UILabel size doesn't resize the StackView that contains it

guys... I have a button and a vertical stackView with 2 labels inside it. When I tap the button I want to decrease/increase the font size smoothly using animations.
The following code do the animation (within an animation block), but the stackView doesn't resize it self:
self.trackingStatus.transform = CGAffineTransformScale(self.trackingStatus.transform, 0.5, 0.5);
When I use the following code, the stackView does resize, but I don't think you can animate that property:
self.trackingStatus.font = self.trackingStatus.font.fontWithSize(11.0)
Besides the problem with stackView the CGAffineTransformScale makes the text distorted. Could you help me with those two problems?
Thanks a lot!

Convert UIScrollView contentOffset and contentSize to layer position and bounds properties

I have a UIScrollView displayed in fullscreen holding a UIImageView that fills the contentView of the scrollView. I added a method to register the contentOffset and the contentSize of the scrollview at a specific pan and zoom.
I'm trying to convert those coordinates to a CALayer that I can animate using the position and bounds in order to animate a pan and zoom to the desired point.
How to convert the contentOffset and contentSize of a UIScrollView to a CALayer bounds and position properties. The CALayer is a screen sized CALayer and is add to another screen sized CALayer.
Looks like I just had to ask the question to finally answer my own problem!
set the anchorPoint of the CALayer to CGPointZero
then set the bounds size to the contentSize
set the position to the negative contentOffset {-contentOffset.x,-contentOffset.y}
Finally.

Resources