I have a UITableViewController with a custom UIView as a subview. When I rotate the iPhone from portrait to landscape orientation the UIView subview rotates correctly but does not resize correctly. How can I resize the custom UIView when the device is rotated?
Set the UIView's autoresizingMask like so:
myView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
This should mean that the view resizes itself automatically on rotation.
Related
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
I create a UIView according its superview's frame. Its superview's frame is always portrait one (568, 1024) actually this application only support for iPad's landscape left and right. How could get a landscape frame when init a UIView?
I'm looking for a way to move a UIView offscreen with a swipe gesture. I got everything set up, but noticed that the code below moves the panel down, rather than offscreen in portrait mode. Is there a way for me to specify "Move UIView to the right by x pixels, regardless of device orientation or autolayout? Maybe dynamically changing the "leading space to superview" is the answer?
CGPoint sidePanelCenter = self.sidePanel.center;
float width = self.sidePanel.bounds.size.width;
self.sidePanel.center = CGPointMake(sidePanelCenter.x-width, sidePanelCenter.y);
Set the NSLayoutConstraint that sets the UIView position as an IBOutlet and change it in code instead of the center property.
I have an image as a subview of a UIScrollView. I want the image to initially fit the screen's bounds using autoResizingMask and contentMode (UIViewContentModeAspectFit) property of UIView. When the scrollview's frame is changed to make room for the keyboard, I don't want the child image view to scale down to fit the smaller frame. I can't disable autoResizeSubviews on the scroll view when it is created because the child view must be re-sized once at the beginning. Right now I can turn off subview re-sizing when the keyboard appears and re-enable it when it dissapears. This seems to work fine but seems hackish. Is that an acceptable way to do it or is there a better solution? Thanks.
Don't worry about the autoResizingMask since it's a subview of the UIScrollView.
The autoResizingMask on a UIView allows for the view to be automatically resized when its parent view's frame has been resized. In this scenario, it sounds like your scrollView's frame is being adjusted vertically to accommodate the keyboard's on screen frame. When the parent view's frame shrinks, so does your UIImageView, which means it works as designed if you're using UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight as the autoResizingMask of your UIImageView.
Instead of using autoResizingMask on your UIImageView, you should manually set its frame to be the same size as the UIScrollView's frame via the bounds property:
imageView.frame = scrollView.bounds;
Then let's set the scrollView's contentSize to be the same size as the imageView.
scrollView.contentSize = imageView.frame.size;
This way, your imageView should be the full size of your scrollView, and won't move if you adjust the size of the scrollView frame.
I want to have an UIView with width=480 and height=640, centered in the middle of my master view.
I want this to happen both in landscape orientation and portrait orientation, but now if I design it for portrait orientation, when I'm turning the device to landscape, my UIView has width=640 and height=480.
Any solutions for my UIView to keep it's sizes in both orientation types?
you can implement viewDidLayoutSubviews (in UIViewController) or layoutSubviews (in UIView) to reposition the view.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.myCustomView.bounds = CGRectMake(0, 0, 480, 640); // update size
self.myCustomView.center = self.view.center; // update center
}