UIButton inside UIView goes out of bounds - objective-c

I'm struggling with a problem that probably it's really stupid.
I've created an UIView and inside the UIView I've placed an UIButton and a UISwitch.
The UIView scales it's width based on the screen size keeping from left and right 45px, the UISwitch keeps it's frame size and the UIButton has its frame size changed based on the UIView frame size.
The problem is that the UIButton's text goes out of bounds for no reasons, this is the result I get:
The Blue background is the one of the UIButton and the Yellow background is the one of the UIView
I'm not able to align the text of the UIButton on top, this is what I've tried:
[_privacyButton setTitleEdgeInsets:UIEdgeInsetsMake(0,0,0,0)];
_privacyButton.titleLabel.baselineAdjustment = UIBaselineAdjustmentNone;
And also from the Storyboard I've set the vertical aligment top
Please someone help me, this UIButton is driving me crazy

You need to set constrains for the particular unbutton, i am unable to see you uiswitch, where you place it?.

Related

Scaling a UIView with UIPanGestureRecognizer

I have a rectangle UIView with a UIWebView as a subview, and I want to change the scale when pan is detected on the upper left corner. I already have another small UIView in the upper left corner so the scaling should start from there. I know this can be done by UIPinchGestureRecognizer but having a UIWebView there will be an obstacle for that. I've added a UIPanGestureRecognizer to the main UIView so it's movable. but I want to check if the pan is from the small UIView in the upper left corner and from there change the scale transform of the UIView. So how to do that? Also is it possible to change the scale horizontally/vertically depending on the direction I'm panning the small UIView to? Also is it possible to set a minimum/maximum scale so the UIView won't scale after that?
Thanks
Maybe there is something that you need?
http://rogchap.com/2011/06/10/ios-image-manipulation-with-uigesturerecognizer-scale-move-rotate/

UIScrollView doesn't work well with IB

I have a screen full of different UI objects that I need to scroll if on a 3.5 inch iPhone screen. I've added the ScrollView and setEnabled to YES but it still doesn't work. I'm thinking I should just code all the objects instead of using the IB and then add them to the scrollview. If I use a view with a scrollview on top with a view on top of that, then add them all to the subview, they lose their positioning. As for the constraints on the IB, there are simply too many objects and with hours spent on different constraint use, that will not be an option. Thanks for any suggestions and help.
Try to set the content size to be the size your frame, which is this case your view controller since you mentioned its "a screen full of different UI objects"
self.scrollView.contentSize = self.scrollView.frame.size;
then set scrollView frame to be the size of the view's frame
self.scrollView.frame = self.view.frame;
UIScrollView wont scroll, if the contents inside of the UIScrollview, are small enough to view without scrolling.
So if you have a UIView obj inside of your UIScrollView and that UIView is not Bigger than the UIScrollView, by default the UIScrollview will not scroll.

UIImageView fit to View frame size

When I create a new ViewController and I drag a UIImageView to this, the UIIV grows to fit fullscreen with the width and height from the screen. If I change between 4 and 3,5" screen, the UIImageView changes his height dynamically.
BUT, when I try to insert an UIImageView to a view with more elements, this UIImageView is setted with 4:3 ratio size, and if I try to resize this to fullscreen, when I change between screen sizes, a part of the imageView is hidden.
How can I fix it?
Short Answer: use Auto layout
Long Answer:
select imageview, add left, right, top, bottom constraints (all equal to 0) to tableview
select imageview, update frames

How do I resize a UIView and force its subviews to resize

I have a UIScrollView with a UIView as a subview. The UIView has a bunch of data entry fields arranged vertically - essentially just a fixed format data entry Form.
I want to keep the UIView's vertical size and adjust its horizontal size to match the size of the UIScrollView which changes depending on the orientation of the device. Note that this is all placed in the Detail view of a UISplitViewController.
So the user will have to scroll vertically but not horizontally as all the text fields on the UIView should resize themselves to fit horizontally on the screen.
Currently if I resize the UIView by changing the frame width to match the UIScrollView's frame width then the UIView subviews (the text fields) don't resize themselves according to the constraints setup in IB. The UIView just seems to get clipped. There is no horizontal scrolling so this aspect is working correctly.
I have autoresize subviews set on UIView and on UIScrollView.
Any tips on what to do here ? Also where would I put code to resize the UIView if the device orientation changes ?
Additional information.
I created the UIView in IB as a separate view in the same NIB as the DetailViewController containing the UIScrollView. Because it is much taller than the UIScrollView the only way I can find for creating it in IB is if I set it up as a separate view of the desired width and height. I then create an IBOutlet and add this view as a subview to UIScrollView in the viewDidLoad method. This all seems to work find with the views all displaying correctly, with the exception that the UIView subviews are not resized horizontally.
Any suggestions on what I may be doing wrong here?
Since you are using not putting the view inside scrollview directly from the xib, the IB doesn't provide the options to give constraints that has anything to do with superview. You might have to add the constraints programatically.See here.
EDIT:
Also try using the below on the view (haven't tried, should work according to documentation, but not sure with auto-layout):
self.view.autoresizesSubviews = YES;
Or if you don't want to use auto layout at all then the earlier method of setting the view to expand (horizontal/vertical) in the size inspector would do. For this you have to disable auto-layout. Select xib-> File Inspector -> Uncheck auto-layout checkbox
OK after more discovery I think I have found the right way to do what I am trying to do so i thought I should leave a note regarding this. Remember I am trying to create a scrollable form that resizes its width but not its height so the user only has to scroll up and down to access fields.
To create a large fixed size form that requires scrolling on the device make sure you set the ViewController size to Freeform in IB. Then you can create the view to be whatever size you want in IB and at runtime it will resize to the devices size.
Place the UIScrollView (I call it the scrollView) in the main view and pin it left and right and top and bottom (i.e set constraints using IB)
Place a UIView (I call it the contentView) in scrollView and make it the same size as the scrollView and also pin it on all sides to its superview (the scrollView)
Now add all the labels and text fields are required to the contentView and make sure you add vertical constraints from top to bottom and left to right so that autolayout can figure out the width and height in order to calculate the scrollView.contentSize
Set the contentView width constraint as a fixed size to make it look reasonable in IB. Bear in mind we want the width of contentView to always match the scrollView width so the user does not have to scroll sideways, only up and down. We will set the proper width in code at runtime as I have not found any way of doing this in IB only. Perhaps setting priorities on constraints might achieve this but I think UIScrollView won't do this for you.
Now add a property the ViewController.h file and connect this to the contentView width constrain you created in 5) above.
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentViewWidth;
Finally create a viewDidLayoutSubviews method in ViewController and add the following code to set the contentView width to be the same as the scrollView width.
- (void)viewDidLayoutSubviews
{
self.contentViewWidth.constant = self.scrollView.frame.size.width;
[self.view layoutSubviews];
}
If things don't resize properly check all your constraints are correctly set. IB seems to do some things that seem strange to me. But finally I have it working with what appears to be minimum coding.
You can also resize vertically in the same way as long as you set the constraint priority on subviews in contentView to be lower than 1,000. Also set a greater than or equal to size with a high priority if you don't want it smaller than a certain size.
If anyone can figure out how to set the contentView such that it resizes its width to match the scrollView using only IB constraints I would love to know how.

UIImageView overlapping effect inside a UIView

Check this URL http://krystalrae.com/
Scrolling down you will see a girl's cloths are changing on mouse wheel scrolling.
I have to create a iPad application where 3 images will appear likewise. The difference will be that in my case image change will occur horizontally rather than vertically in website. Also, i have to make it inside UIView with events touchesBegan, touchesMoved, touchesEnded and touchesCancelled
Help will be appreciated.
Thanks.
From your comment I gather that the problem is the resizing of the images in UIImageView when changing the bounds of the view.
You can set the contentMode of the image view to something else. The default is UIViewContentModeScaleToFill which is not what you want.
You could, for example, set the lower image view to UIViewContentModeBottom, and the upper image view to UIViewContentModeTop.
Don't forget to make sure your image views have sett the property maskToBounds set as YES.