my collection view cell is full size..i have collection view cell and it contains button..i successfully display all button with it's title in collection view cell. but i am having one issue that some button title is too large..i want to change it's widht based on text...how to set button width based on text..i have vertical collection view
my array is
var arr = ["butto1 butto1 butto1","butto1 butto1butto1butto1","butto1","butto1 butto1butto1butto1"]
I have searched so many time but still i haven't point out
...any on help me..Thank you
You haven't given much information that would help in diagnosing your problem.
The button should automatically resize to fit the text unless you have set constraints that stop it from growing.
If you have set a left and a right constraint to equal a constant then it will not be able to grow.
As far as I can tell, you have two options.
Only set 3 out of 4 constraints. For example the following image has 3 constraints set which allow the button to grow downwards.
Set the right constraint to "Greater than or equal to" instead of "equal" in the interface builder. This will allow the button to grow to a maximum size which is specified by the constraints.
Also make sure to set your button to word wrap so that text continues on the next line.
Related
I am trying to set margins in the UITableView's cell, but it doesn't work. I set all constraints and nothing. The Labels are always in the same place - left top corner, but in the Storyboard it looks like I want. If I set the layout of a Label to Translates Mask into Constraints is fine, but then I can't set autoresize Labels. I have already made cells using the Automatic layout, but in this case I really don't know what's going on.
Based on the screenshot you posted I believe you're missing a trailing constraint on your City Label that goes from the right edge to the right edge of the content view.
I always make this last trailing constraint a "greater than or equal to" constraint to allow for the length of the content and different device widths.
I have a collection view with many different cells in it. Each cell takes up half the width of a page, and contains an image and a label under the image.
I am starting with all of the labels being truncated, along with a "Read More" button that is supposed to expand the label.
The code to do the expanding is working, but the problem is that if I click the button on a cell in the top row, and the 2nd row also has 2 cells in it, I need those 2 cells to move down the page when I click the button as well. Right now, the text is technically "expanding" but then just being truncated due to having no height left.
I believe I need some sort of invalideLayout combination with something else to make this happen, but I can't seem to piece together how I would force all of the cells to move downwards as well.
The "Read More" button is attached to a function call that updates the number of lines for that text from "3" to "0" and reloads that cell.
Thanks in advance!
I would like to build a TableView where when the user clicks on a cell it expands to show more information. My question is how do I use Autolayout to arrange the multiple items in each cell.
Each cell will always be the same size, whether it is collapsed or not, so the sizing isn't dynamic.
The first problem I have is how to use Autolayout to arrange all the items in the cell. Before Xcode 7 I was successfully using Autolayout where I would pick a label-button-view to arrange, click Editor > Align > Trailing/Leading/Top Space, to.. etc. This is now greyed out and I don't know how to replace my old strategy.
Each cell has two rows of items. The first row shows all the time, the second only shows on collapse. Below is a picture of how the cell will look when it is collapsed:
The first row is a bit trickier because outlet1 and outlet 2 will have variable sizes. I would like 'label' to come right after label1, no matter how long or short that outlet happens to be. As arranged currently, there is a variable amount of space between the two.
What I'm looking to achieve in row 1 is basically exactly like Venmo:
Notice how 'paid' conforms to the size of the two names in the first row.
The second row has two buttons and an outlet which will always be the same size.
To sum up - how can I layout these elements in the UITableView for iphones4 thru 6S - and then how do I make this cell a collapsible cell? The construction of these cells seem to work as a system, not isolated from the whole - which is why this is a 2-part question.
is this what you want to achieve?
I'd like to use a UItableView to show a day Calendar. Each row corresponds to one hour. I need to show the hour between 2 cell of my tableview.
Like this :
(source: free.fr)
And this is my UITableViewCell :
(source: free.fr)
In the first screenshot, it works perfectly but if I scroll down then scroll up, my time label is cut like this :
(source: free.fr)
Have you any tips to figure out this problem using a tableView ?
The way you lay out your cell now is fragile, because the order of painting the cells on screen matters a lot. Try moving the content up so that your buttons are flush with the top of the cell, and the time label fits into the cell entirely. Add a thin header view to your table to make the top cell appear normal. Keeping the content of a cell entirely within its bounds should help you maintain reasonable scrolling speeds.
EDIT : You could also put a second clipped label at the top of your cell, and make its content identical to that of the label in the prior row. You would need to take special care to hide that label in the top row, but otherwise this should make your table immune to changes in the rendering order of its cells.
Make the background color of your cell clear. As you scroll up the z ordering of your cells get reversed and the lower cells overlap the higher ones causing this clipping.
I have this interface with multiple UILabels.
On view loading i populate white labelled values with some data from a db.
The problem is, some of that fields are potentially too long for the interface, so i'd like to compute the total height of one label once the text is word wrapped and reposition the 2 labels below (shifting the Y coordinate) accordingly to the previous label's height.
All of this should go inside a UIScrollView to let the user scroll those labels vertically.
Any chance i can do this easily with some control i still don't know, or do i have to do it manually?
Thanks
You'll need to use the NSString UIKit Additions to compute the height you need to set on your UILabel, and then adjust the other controls appropriately.
Specifically, I think you want to use sizeWithFont:forWidth:lineBreakMode: to get the rect for your UILabel.
Alternatively, you could use a UIWebView and display the information as HTML. I don't know if it's necessarily less work, but you'll get a layout that automatically adjusts to the size of its contents.