uistackview

Programmatically add subviews to a UIStackView

社会主义新天地 提交于 2019-12-04 03:48:14
I'm trying to implement a table view cell that displays a series of icons that represent home amenities (e.g. towels, wifi, laundry, etc.). The cell could potentially display a large number of amenities (depending on how many the home has), so I'll display a maximum of three and indicate that you can view more by clicking on the cell if there are more than three. Here is what it should look like (from Airbnb's app): I am trying to do this by dynamically adding UIImageViews to a UIStackView in the table view cell. I am using a UIStackView with alignment set to "Fill" and distribution set to

Constraints to center and object between two objects

喜你入骨 提交于 2019-12-04 01:28:06
My design requires that a button is centered between two other objects. One of the objects is in the vertical center of the view (green). The other object is some distance from the bottom edge (green). Now the task is to center the third object (red) between the other two. I am using xcode6's new constraints and my view is in wRegular hRegular mode. This would be easy with code, but I am trying to use the storyboard to accomplish this. There are a number of approaches: In iOS 9, the easiest would be to define a vertical UIStackedView with a distribution of "equal spacing" and then

Stackview exchange or change order of views

北慕城南 提交于 2019-12-04 01:14:09
Stackview containing array of textfield is embedded in scrollview. I want to change the order of the text fields on some actions. The way to remove and add the textfield results in distorted view. I also tested by removing from scrollview. Normal stackview too the exchange does not appear properly. I am using indexes to change : stackView.removeArrangedSubview(localityTF) stackView.insertArrangedSubview(localityTF, at: 2) It is strange behaviour, but problem with the autolayout system, that should be updated before you can add localityTF back. Also don't forget that removeArrangedSubview does

First Baseline and Last Baseline Properties in UIStackView

為{幸葍}努か 提交于 2019-12-04 00:43:37
What effect does First Baseline and Last Baseline properties on the subviews of a UIStackView ? In fact, what does these property mean? Suppose you have a two-line text view (or field or label or button) and a three-line text view, and you add them to a horizontal stack view. Do you want to align their first lines, or their last lines? That's the difference. .FirstBaseline : .LastBaseline : Note: I increased the vertical content hugging and compression resistance priorities to 1000 (required) to get this to work properly. 来源: https://stackoverflow.com/questions/33932846/first-baseline-and-last

How To: Self-Sizing Custom-View from XIB with StackView View in iOS

左心房为你撑大大i 提交于 2019-12-03 01:24:10
I've recently started diving into iOS development with Swift again and am now looking into a custom UIControl. For layout and flexibility this custom view is built using a StackView. What I want to achieve ... ... is basically to simply have the same functionality with the StackView that I usually have when I drag it directly into the storyboard - where it resizes to fit no problem. This essentially the same as self-sizing tableview cells. Showcase I can reduce my CustomView to a simple example: It's a StackView with three labels in it, Alignment set to Center , Distribution Equal Centering .

UIView dynamic height inside UIStackView

帅比萌擦擦* 提交于 2019-12-02 17:54:27
问题 I currently have a Stack View setup with a bunch of different objects inside of it, and I'm trying to add a view to it. The view will have a dynamic number of labels added inside of it programmatically at run-time. When I put the view inside of the stack view, I get errors with the constraints, which get fixed by adding a height constraint. However, I don't know the height of the view initially so I can't constrain this. Is there any way to have a UIView inside of a StackView auto-resize

Unable to simultaneously satisfy constraints when update height constraints of imageView swift 4

大憨熊 提交于 2019-12-02 16:21:14
问题 I have a stack view that look like the figure below: So I change the height of the image programmatically to make it fit the image that download from my server,if dont have image,the height constraints of image will set to be zero. Here is my code to doing so: let imageUrl = URL(string :imageString) if let data = try? Data(contentsOf: imageUrl!) { guard let actualImage: UIImage = UIImage(data: data) else{ print("No image!") ImageView.image = nil defaultImageHeightContrainst =

How to change the background color of UIStackView?

社会主义新天地 提交于 2019-12-02 14:46:14
I tried to change the UIStackView background from clear to white in Storyboard inspector, but when simulating, the background color of the stack view still has a clear color. How can I change the background color of a UIStackView ? Dharmesh You can't do this – UIStackView is a non-drawing view, meaning that drawRect() is never called and its background color is ignored. If you desperately want a background color, consider placing the stack view inside another UIView and giving that view a background color. Reference from HERE . EDIT: You can add a subView to UIStackView as mentioned HERE or in

Aligning multiple runtime generated UILabels in a UITableView

北慕城南 提交于 2019-12-02 13:19:46
I have a UITableView that needs to support content by listing style something like But the tricky part is that the amount of "Label" will vary with each cell, some may have only 4 but also up to 12. Also the "Value" can be either a single word or short phrase up to two lines(like in the image above). So I decided to use UIStackView to help me pack and size my UILabels used to display this. I am currently stuck at a problem when the "Label" varies in length like: I need the leading end of the "Values" to be aligned like the first image even though the "Label" vary in length. Is there a

Unable to simultaneously satisfy constraints when update height constraints of imageView swift 4

风流意气都作罢 提交于 2019-12-02 07:42:53
I have a stack view that look like the figure below: So I change the height of the image programmatically to make it fit the image that download from my server,if dont have image,the height constraints of image will set to be zero. Here is my code to doing so: let imageUrl = URL(string :imageString) if let data = try? Data(contentsOf: imageUrl!) { guard let actualImage: UIImage = UIImage(data: data) else{ print("No image!") ImageView.image = nil defaultImageHeightContrainst = ImageHeightContrainst.constant ImageHeightContrainst.constant = 0 layoutIfNeeded() return } let imageHeight =