I have UITableViewController and I insert UIView on top with elements in view. I get problem with height of UIView. All UIlabel are multiline 0 for dynamic height. I want to make UIView height flexible with respect to UILabel in view (by attach image below). I have made it using storyboard and set autolayout but doesn't work for me. Can I make it ? Thank a lot!
Related
I have UIView in separate .xib file and I make UICollectionView in it.
To add collectionViewCell I made separate .xib file.
Now below collectionview I want to add UIView.but my problem is I set height of collectionview dynamically by using code.
But when I add this using autolayout constraint to add view below bottom of the collectionview but view will add on distance where It put on UI.
I want that first setup collectionview than view placed below it.
Problem screenshot 1
Below UIView constraint I have already set 2
Thanks
Nirav Zalavadia
Instead of adding the UIView below the UICollectionView, place the UIView in the bottom of the screen.
Then, use a constraint from the bottom of the UICollection view to the top of the UIView.
Recently I'm testing to do a very complicated view in xcode using nothing but scrollview and programatically added imgviews. Like this
What I did is, I put a UIView called contentview in a scrollview and I then add a lots of ImageViews in the contentview. The real thing is much much complicated than the illustration so I can't use tableview. Sorry for the poor illustration but I think you will get the idea.
Everything is fine until I tried to add the last constraint in code, which marked red in the picture. When I did it, it breaks the entire chain of constraint.
In another word, this is working
V:|-[view1(30)]-[view2(30)]-[view3(30)]
This is not
V:|-[view1(30)]-[view2(30)]-[view3(30)]-|
And btw, what is the proper way to do it anyway? I tried to add imageviews directly into the scrollview itself but I can't make the view to use autolayout like this
H:|-[view]-| The superview here is a scrollview
The result, this view will be very narrow in width. I guess scrollview doesn't have a width value or sth? that's my guessing. That's why I added a contentview as a holder for all the imageviews.
Try this, it will work. - http://natashatherobot.com/ios-autolayout-scrollview/
To summarize -
Add scroll view to main view.
Add a UIView (lets call it content view) to scroll view.
Now add all your views to the above UIView.
For each of them set the constraints so as the separation on all sides is 0. And finally add equal height and equal width constraints between the content view and the main view.
Ok, finally I did my own work.
The key to make scrollview and contentview and everythin else inside work automatically using nothing but autolayout is this.
1, Manually add scrollview to self.view, and a contentview to scrollview. Set both scrollview and contentview to setTranslatesAutoresizingMaskIntoConstraints(false)
2, set scrollview to H:|[scrollview]| and V:|[scrollview]|, set contentview to be H:|[contentview]| and V:|[contentview]|
3, Now try to add Views to content view and set their constraints to the contentview. You should see that when the views are larger than the current window size, the scrollview started to scroll. IE, this setting will automatically set the scrollview.contentSize using autolayout
I have a view-based NSTableView. I positioned the textField and other elements in an NSTableCellView in Interface Builder with autolayout. How can I get the height for the cell based on its autolayout parameters?
This answer is the closest I have found to what I am looking for, but it is written for iOS and the systemLayoutSizeFittingSize method does not exist on NSView.
You could put the views inside your table cell view into a separate NSView (let's call this view contentView). Set Auto Layout constraints for the contentView so that it aligns to its parent view at the left (leading), top and right (trailing). Make sure the subviews of contentView resize their parent view. Create an IBOutlet on that view in your NSTableCellView subclass. To calculate the height, call fittingSize on contentView which should get you the minimal size of your subviews based on the constraints.
I have a view-based NSTableView.
I have created a NSView to insert in this NSTableView as a row.
In the xib defining the NSView, the latter has a width set to 280.
When I add my NSView to my NSTableView, the width of the former is changed to be equal to the width of the NSTableView.
Is there a nice way to prevent this behavior ?
I thought of including my NSView in another one, but I feel it is a bit hacky.
If possible, I would like a solution that only involves settings of the NSTableView. This NSTableView is indeed to be populated with many differents NSViews.
As I mentioned in my comment to your previous question. You want to add your own views as subviews of NSTableCellViews. The NSTableCellView will be set to the width of the table, but your child view can be any width you like.
this might be naive, but what happens if you uncheck Autoresizes Subviews in TableView's Attribute Inspector?
I have a UIViewController that has an image and label at the top followed by a UITableView. In the IB it looks perfect, but when I run the application in the simulator the UITableView is stretching and taking up the entire screen.
I've turned off all autosizing and set all of the values for stretching to 0, but it's still taking up the entire screen. I even tried some advice I saw on another post which suggested putting the UITableView in a UIView that was sized, but that did not work either.
Any suggestions on how to stop the UITableView from resizing and filling the screen? I am running XCode 4.2.1 with iOS5.
You can give frame size to your tableView like this-
1) make your tableView's IBOutlet property in .h class, and synthesize in .m class.
2) connect it in Xib.
3) than in your .m class place this code in viewDidLoad-
tblView.frame = CGRectMake(0.0f, 30.0f, 320.0f, 50.0f); // you can give any size to your table