Setting custom accessoryView make a margin to contentView from right side - uitableview

When I have set accessoryView I get a margin from right side contentView in 15px (or 20px if scale equal 3). I tried remove this gap, but without result.
Somebody have a idea what is it? how remove this or reliably calculate size of gap?
On screenshot:
1) custom accessoryView zero size
2) default accessoryType

Related

Add padding to sides of text in a button

Using Xcode's storyboard, how can I add padding to the left and right of a UIButton's text? I can't for the life of me figure out how to do this.
Here is my button:
I want the button to "hug" the text and then give padding of 32px on the left and right sides of the button.
But when I try to add a Title Inset, it just squeezes the text to a point where it's almost not showing:
So how do I adjust the button's padding properly?
Ensure following things are done for the Button in storyboard.
Update Content insets value for Left and Right as 32px in Size
Inspector in storyboard.
Also, ensure Content Compression Resistance priority -
Horizontal value is high (751) for safer side.
Remove if you have any width constraint for Button, if possible.
Do not update Title insets. It will not work as you expected.
I have tested this. It's working for me.

How to set a UILabel as a percentage of the width of the UICell with autolayout

I'm wondering how to set a UILabel's width expressed as a % of the Cell's total width? I'm using AutoLayout. Normally I would click on the label and set the EqualsWidth to a parentView and then adjust the multiplier so I set the width as a % of the parentWidth. But using InterfaceBuilder that option does not seem to be available within the Cell.
However I'm wondering maybe it has something to do with setting the preferred Width: I'm using ios8+ and have read that implicit widths are not available for ios8?
What I am hoping to achieve is that Label 1 and Label 3 are both 15% the width of the Cell and Label 2 has leading and trailing edges pinned to UIImageView and Label 3 that will allow it to grow and shrink depending on the width of the device.
Steps you should do to achieve your goal of setting percentage width of any subview inside cell:
Add UIView to your cell and pin it to every edge - we have to add custom container view in order to be able to add "Widths equally" pin later on.
Add UILabel to previously added UIView container. Lets say we want to add left side label, so add 3 pins to it: left, top, bottom.
You can see now that you have error in your constraint setup. So lets fix it and add "Widths equally" pin. Select 2 views in View Controller Scene menu - the container and the label. Go to XcodeMenu/Editor/Pin/ and select "Widths equally". Now you should see no errors in you constraints setup and the label should have same size as the container. (Please note that sometimes you have to refresh frames of your views after setting constraints, so if you see "yellow" warning icon don't be afraid and just click on it).
Now if you have all your constraints we need to set actual percentage value. Open tab Size Inspector, click "Edit" title on constraint added in step 3. and change Multiplier value to 0.15 (15%).
Please note that, if you would add label using same technique but for right side, then you would need to set Multiplier value to 6.66 (= 1.00 / 0.15).
Cheers!
You can set width constraint and then create an IBOutlet for that in UITableView cell and change constraint.constant value in layoutSubView method of tableViewCell

UICollectionViewCell extra padding appears

I have made a prototype cell for UICollectionView and set some dimension for that. In the cell I have added Thumbnail(and other objects) and set constraints so that thumnail fills the cell completely. However there is still some space left between. I have set background color in cell to demonstrate that. Attached screenshot for the same. Same thing happens in tableview as well.
One hack could be to set negative value in constraint. But I want to why extra space is coming, even constraint are set to match to cells top, left, bottom, right.
The extra spacing is due to margins, while selecting any constaint just uncheck relative to margin in selected constraints
open second item drop down
there will be relative to margin and
uncheck it
Your content of the cell has an x of 8 and y of 8 which will result in having a padding as when you attach a constraint to superviews, the constraints will add as margins. Just change the x and y to 0 and update the constraints!
[EDIT]:
To elaborate the point:
1.clear the constraints of the view inside the content view of the cell.
2. make the view's x and y as 0.
3. add constraints as previously, you did, UNCHECK "constraints to margin".

UITableViewCell dynamic constraints

I am making filling a UITableView with custom cells of dynamic heights. I am using the methodology as described here.
For the purposes of simplicity, say my cell contains 2 UILabels as shown below.
The purple UILabel will remain the same height for all cells in the UITableView. In this case, the purple UILabel is taller than the green UILabel. I would like the constraint between the bottom of the purple UILabel and the bottom of the contentView to be 8.
However, there is a second scenario that is possible as shown below.
In this case, the purple UILabel is still the same size as the first case (even though it looks smaller, but since the overall cell height is larger, relatively, it looks smaller), however the green UILabel is much larger. In this case, I would like the constraint between the bottom of the green UILabel and the bottom of the contentView to be 8.
Now my dilemma is that I can set either one or the other (I am using storyboard). But I cannot think of a way to make both possible at the same time. My guess is that you would need to adjust constraints programmatically during runtime depending on the size of the green UILabel.
Any thoughts?
I am using XCode 6.1.1 in Swift.
Thank you.
If the purple label is always the same height, then you should just set the height constraint of the element, rather than setting its bottom constraint to superview as 8.
For the green element, perhaps you could select both that element and the contentview and set them as having equal heights from the "add new constraint" pane at the bottom of the storyboard window. Then, select that constraint and edit its multiplier value in the attributes inspector to some value less than 1. That would make the element's height always be some percentage of the parent view's height. You could tweak that around until it gets you close to the desired 8px from the view below it.

Applying autoLayout constraints to multiple objects

I am playing with autoLayout constraints in iOS
My use case is this way,
I will better explain with images
I am using a custom cell for UITableViewCell, through autolayout I have set constraints for text and divider line below and they obey autolayout constraints. Now you can see the yellow vertical strip on the left.
I have not set any constraints for it, so when the cell height is normal, it covers the whole cell, but when cell height increases, it doesnt increase and fill the whole cell. I am not able to make its height flexible w.r.t to cell.
I want to expand the yellow strip to cover the whole cell.
So how I can achieve this.
You can make height of yellow strip flexible by setting 2 constraints.
Set both top space and bottom space to container (cell's content view) to 0.
Ensure there is no constant height constraint for it.
You need to set constraints to the yellow view. By default it would apply its own constraints at runtime.
To the yellow view add TOP , BOTTOM , LEADING , and TRAILING constraint. DO NOT ADD A HEIGHT constraint.
Make sure the TOP and BOTTOM constraints of the yellow view are pinned to the cell's content view.
Let me know if it works.
Cheers

Resources