Big Subview to Fit in Another Small Subview - ios

Im trying to create a secondary view to my main view. This subview needs to be of small height and it needs to fit another big UIView with a label in it.
Problem is that when I'm using UIView addSubview, the third UIView will be shown out of bounds of secondary UIView.
For ease of understanding my situation, I have created those Subviews using Interface builder with the photo and the result on simulator with the photo.
Any help would be much appreciated.
Thanks
Interface Builder
http://postimage.org/image/ofi3m05v3/
Simulator
http://postimage.org/image/x2qps3w2f/

You need to activate the clip to bounds property of some of those views.
fooView.clipsToBounds=YES;
That should solve your problem. Just set the appropriate views to clip to their bounds.

Related

UIViewController subviews added in interface builder not showing up

Ok so basically I just used the interface builder with auto layout to add some subviews and constraints to my UIViewController. My app is supposed to segue to this view when the user wants to take a photo. I laid out a few camera buttons on a black, square UIView that will serve as the camera view once I have programmed it. Since I wanted to make the camera view a square, I also had some extra space where I just made a label that says "Take a photo!" This is how the interface builder for this view controller looks:
And this is how the same view looks when I run the app:
I'm guessing it's something simple that I'm missing that's causing this problem but I will be grateful to anyone who can help me!
When you are using autoLayout you should set all needed constraint to the view. Otherwise it is an ambiguous layout problem, and the system is not knowing where to set your view
If you want the height to be the same like the width set the aspect ratio constraint to your view
And be sure that the multiplier of constraint is 1
Bring that subview to front, putting all other views to its back
try it will work
parentView.bringSubview(toFront: childView)
This method can also be used to bring any subview to the front, even if you're not sure where it is:
childView.superview.bringSubview(toFront: childView)

UIScrollView and two-way scrolling

I'm having some trouble working with UIScrollView in my current project. My intention is to have a variable-size drawable canvas which can extend beyond both sides of the screen, and whose size is determined by the user at runtime. For this purpose, I put in a UIScrollView with a Content View inside of it in my View Controller. Unfortunately, Interface Builder keeps pestering me to define the X and Y axes of my Content View as a constant sizes which isn't possible given my specifications. I've even set the ScrollView.contentSize programmatically in my viewDidLoad method and Interface builder is still giving me errors. All other tutorials I've seen have only talked about one-way scrolling with UIScrollView, so here I am. Here's some screenshots of my storyboard hierarchy as well to make things more clear:
Hierarchy
Errors
Does anyone have any experience/workarounds for this kind of problem?
Interface builder is TRYING to be helpful and make sure that you don't have arbitrary constraints on your content view.
Remember that Interface Builder just cares about the initial state of the views it loads. It does not care what you do with them after they have been loaded.
Make IB happy by giving it some rational initial size for your content view. Then programatically after your scroll view loads you can resize the content view and set the scroll view's content size programmatically.

scale subviews to fit inside uiview

What I'm trying to do is very simple...i think. I want to make sure all the subviews within a view in my view controller are scaled to fit. Inside it.
My view controller has a menuview (subclass of uiview). Within that there are uiimage views, labels, and a button. The MenuView class I created has a nib file with a uiimage view that I want to scale to the size of the menuview depending on the device used. I'm not sure if the menuview is not staying constrained to the screen or if the uiiimage isn't, but when i run my program the menu runs off the screen.
Question:
- Can I force this (uiview and/or uiimageview) to stay on the screen using storyboard (programmatically is ok, but would prefer to try with storyboard)?
If anyone can point me to a good introduction to auto layout view and understanding the mainstoryboard that'd also be appreciate because it's insanely frustrating.
Screenshot: in the image below you can see I have a letter image that I want within the limits of the screen.

Using interface builder to layout a scrolling view with images and text

I have a requirement in my app to display a bunch of information that includes both text and images. It will be quite long, so it will need to be scrollable to access all the content.
I know that I can achive this by programmatically adding different UILabels, UIImages etc to a UIScrollView. But this is a proof of concept, so I'm looking for something a little quicker than having to work out all the positioning and code required. The information is static anyway, and does not need to interact with code.
Is there a way to do this using the interface builder (storyboard or xib is fine)?
you definitely can do that if you simply want a quick interface
1.> you might need to know how long is your scroll view, for example in my case, i set it to 1568
2.> Then i drag all the controls that will fit for the first 568 pixel view onto the scroll view and position them.
3.> Then change the Y value for that scroll view to something like - 500, so you can see the rest of the scroll view, and put everything you need there.
4.> After you have all your controls, and remember to set the frame back to 0,0,320,568
5.> last step, in your code, set SCROLLVIEW.contentSize = CGSizeMake(320, 1568);
I would still suggestion don't hard code all those values, but if you are looking for a quick way to do your interface, hope that gives you some ideas.
Just start a new project with a single view, it will come with a xib or storyboard for its single ViewController.
Create a UIView by dragging it into the workspace and place as many Labels, Images and UI Elements as you want.
Open the xib / storyboard and drag a UIScrollView in as your root VC's root view. Drag the view containing your layout into the scrollview, making it the scrollviews only subview.
Done (almost)!
If you launch your app at this point, you'll notice you can't scroll. That is because the scrollview is "too stupid" to adjust the size of its contentSize property on its own.
You'll need some code here, but it is only a tiny snippet and you won't need to touch it again:
Create a new Category on UIScrollView.
In your category's implementation, do:
#implementation UIScrollView (MyHandyCategory)
-(void)awakeFromNib {
NSArray *subViews = [self subviews];
UIView *contentView = [subViews objectAtIndex:0];
[self setContentSize:contentView.frame.size];
}
#end
Done (for real this time)! This will check the size of the view your scrollview contains and ajust the contentSize after it has been initialized. You can change the size of your content view as you like, no need to play around with hardcoded values or even Interface Builder values!
If it’s just proof of concept I’d have a WebView and a local HTML page you load. Easy-peasy.
I would suggest UICollectionView. It's fairly straightforward. There's a good tutorial here:
http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

Creating a fixed footer in viewport in iOS

I want to create a footer fixed to the bottom of the viewport in an iOS app I'm developing (it's my first one, I come from a web dev background). However I'm having difficulty finding information on how to go about this.
What I have in mind is essentially just 3 rectangular buttons next to each other that are just constantly fixed to the bottom of the viewport. I tried dragging a toolbar into my scene as a starting point, but in the interface builder it's placing itself under my table cell, rather than fixing to the bottom. I feel like this is probably easier to do programmatically, but I just don't know where to start.
If someone could at the very least guide me in the right direction I'd really appreciate it. Thank you.
Okay... create/add custom UIView on your main view (self.view)
and set this custom view's frame = (0, 0, 320 , self.view.frame.size.height - 50) /// change value 50 to as per your requirement.
and add all of then UIControls such like textField, tableVie, button ...etc.. on this custom view.
Don't use a UITableViewController. Use a UIViewController, then add a table view and a toolbar. You'll need to implement the UITableViewDelegate protocol in code and then connect the delegate in interface builder.

Resources