I have a UITableViewCell nib that depending on the data it can show an image or not.
Below, the cell has 2 labels and at the right most the imageView. What I want to do is to remove the imageView (if no image is present on the data) and extend the Label all the way to the right.
Is there a way to have several constraint scenarios on the nib that I could activate/ deactivate?
Constraints on label1
leading, 2. center vertically in container, 3. fixed width
Constraints on label2
Leading space with label1, 2. Center vertically in Container
Constraints on imageview
Trailing space, 2. Top space, 3. Bottom space,
Width constraint : width <= 50 (When there is no image then width will automatically get zero),
Horizontal space between
label2 and imageview = 0 (priority = 250)
See the below GIF:
Related
I have a NSCollectionView which uses a NSCollectionViewGridLayout to create a single row of collection view items. The row can have one or more items and can scroll horizontally is needed, i.e. one row, unlimited columns (one item per column).
The collection view items have a minimum size of 240x160 and have an aspect ration constraint of 3:2 (the width is 1.5 times the height). There is no maximum size.
All the spacing/insets are set to zero so that the items are next to each other horizontally, starting at the left-hand side of the collection view (though ideally I'd like to center the items horizontally if the total width of the items is less than the width of the collection view.)
The collection view is in the top half of a split view. When dragging the divider up/down (vertically), I'd like to resize the collection view items while maintaining the aspect ratio. The problem is that the aspect ratio constraint conflicts with the leading/trailing constraints and causes a constraint exception.
1) I've tried removing the leading/trailing constraints from the collection item view, but then the items are not flush together. I can't have gaps between the items and I can't the items overlapping each other.
2) I've tried removing the aspect ratio and the items resize correctly but don't maintain their aspect ratio.
3) I've also tried setting an aspect ratio on the collection view width such that it equals the height of the collection times the number of items times the aspect ratio, but wasn't able to get it to work correctly (and it seems kind of hack-ish). I also tried a custom layout object but I ran into different errors.
3) I was considering, but didn't try, de-activtating the aspect ratio constraint when the drag starts, and re-acivating the constraint when the drag ends but wasn't sure if this would work (it seems kind of hack-ish).
// setting up the grid layout
NSCollectionViewGridLayout* layout = [[[NSCollectionViewGridLayout alloc] init] autorelease];
layout.minimumInteritemSpacing = 0.0;
layout.minimumLineSpacing = 0.0;
layout.margins = NSEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
layout.maximumNumberOfRows = 1;
layout.maximumNumberOfColumns = 0;
layout.minimumItemSize = NSMakeSize(260.0, 160.0);
layout.maximumItemSize = NSZeroSize;
self.theCollectionView.collectionViewLayout = layout;
(not shown are the constraints in the collection view item xib file)
The desired result is to have:
a) User resizing a single row of collection view items by dragging a split view divider, and they maintain their aspect ratio while being resized.
b) Ideally, collection view items would be centered horizontally in collection view if the items don't scroll horizontally.
I have a textfield of 100 width but i want the size of this textfield change on different size screens in same manner. i do not want to give % constraint of screen to increase size. for example in 6s textfield size is 100 but on 7 size should be change on the basis of screen size.
If you want to use constraints, you have to manually change its value accordingly to screen size. You can drag and drop your constraint properties as outlet
And you can change the constraint by accessing its constant property
self.viewWidthConstraint.constant = 20 //Or desired value
I want to display status on a UILabel. I want it to wraparound at word breaks if it's too long, and I want font size to shrink if not enough room in the UILabel.
UILabel is created in storyboard, and its Lines = 2, and Autoshrink is Minimum font Scale 0.5
But I can't make this happen. Text keeps truncating.
I got it working:
In storyboard:
1. stretched UILabel vertically bigger
2. Lines=0
3. Line Break = word Wrap
4. Autoshurink = Fixed Font Size
I want to arrange eight views around one main central view so that as the main view is programatically moved or resized, the surrounding views keep their same positions. This link shows the layout.
http://homepage.ntlworld.com/bernie.w/Autolayout.png http://homepage.ntlworld.com/bernie.w/Autolayout.png.
Note:
Views 2 & 7 are vertically centred on the main view.
Views 4 & 5 are horizontally centred on the main view.
I'm new to autolayout, so any pointers how to achieve the above appreciated.
Just add horizontal spacing constraints between 4 and Main view then 5 and Main view. Then add vertical spacing constraints between 7 and Main view then 2 and Main view. You should then be able to do vertical spacing 'greater than or equal to' from 1 to 4 then do horizontal spacing 'greater than or equal to' from 1 to 2. Repeat that 'greater than or equal to' process for horizontal spacing and vertical spacing for the 1-3-5, 5-8-7, and 4-6-7 views and you should get the result that you want. Let me know if you have any questions about that.
I have a UITableView with style: "Grouped"
By default, the iOS gives me rounded cells, with a white background and a grey separator.
How can I configure the table so that, for only one section of cells, the cells are rectangular (no border radius) and have no separator? - I wish to use a custom background image on these cells.
Thanks in advance -
bo
You can make them squared off by creating a dummy cell for the first and last cell and setting the row height to 0 for those cells in tableView:heightForRowAtIndexPath:.
You can set the seperator to None and clearColor in the inspector section of the storyboard in order to get rid of the seperators.
Then you can just create a custom background image using backgroundView for the cell in your cellForRowAtIndexPath::
UIImageView *customImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourimage.png"];
[theCell setBackgroundView:customImage];
You can use two kinds of UITableViewCell in the table, original for the standard cells and customized subclass with overridden drawRect to draw the other cells depending on indexPath.