uistackview

Get the frame of a UIStackView subViews

南楼画角 提交于 2019-12-10 15:39:35
问题 I have created a UIStackView in IB which has the distribution set to Fill Equally. I am looking to get the frame for each subView but the following code always returns (0, 0, 0, 0). class ViewController: UIViewController { @IBOutlet weak var stackView: UIStackView! override func viewDidLoad() { super.viewDidLoad() let pView = UIView() let sView = UIView() pView.backgroundColor = UIColor.red sView.backgroundColor = UIColor.orange stackView.addArrangedSubview(pView) stackView.addArrangedSubview

Resizing UIStackView after changing UILabel number of lines

拟墨画扇 提交于 2019-12-10 10:13:42
问题 My iOS app has a tableview with one UITableViewCell with the following layout (1 stackview containing 2 labels and 1 button) When the user taps the button the number of lines of the central label goes from 0 to 2 and will look like this: Now there are two problems here: 1) Resizing the UIStackView 2) Resizing the cell I have found a not-optimal solution for problem 1, which consists of adding an empty view in the stack. (invalidateIntrinsicContentSize was not working). let emptyView = UIView(

UIStackview align left

孤街浪徒 提交于 2019-12-10 04:06:26
问题 I'm trying to align the items in UIStackview horizontally to the left. Is there anyway to do this programmatically? I tried to do this via storyboard but was not successful. For some reason, the items in the UIStackView centers itself. 回答1: If you use StackView setting axis property to "Horizontal", I think you can't align it to the left. But there is a way to make it left visually. set StackView leading constraint with "equal" relationship set StackView trailing constraint with "greater than

Stackview exchange or change order of views

我怕爱的太早我们不能终老 提交于 2019-12-09 15:03:10
问题 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) 回答1: It is strange behaviour, but problem with the autolayout system,

How to change the background color of UIStackView?

回眸只為那壹抹淺笑 提交于 2019-12-09 04:03:48
问题 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 ? 回答1: 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

UIStackView; Equal Spacing Between & Outside Elements

房东的猫 提交于 2019-12-08 20:47:07
问题 UIStackView is awesome, I love Equal Spacing Distribution. But how to achieve the same space also outside of elements dynamically? In my case all elements will have same ratio 1:1 回答1: You can add equal spacing using the story board as shown here: Source: https://stackoverflow.com/a/32862693/3393964 回答2: You can use constraints and give then same height and width. So when you change the dimension of anyone of the component then all components are changed with same dimension. 回答3: I think what

Prevent vertical UIStackView from stretching a subview?

浪子不回头ぞ 提交于 2019-12-08 11:58:20
问题 I have a UITableViewCell with a vertical UIStackView that currently has .alignment = fill and distribution = fill. Inside the stack view, I have a UILabel and a UIImageView. The label should be left aligned and stretch across the width of the stackview (and it does). The image view has a content mode of aspect fit and should be centered in the middle of the stackview. I thought this was working as I wanted it to until I set a background color on the UIImageView and then realized that while

Retrieve the right position of a subView with auto-layout

拟墨画扇 提交于 2019-12-08 02:29:10
问题 I want to place programmatically a view at the center of all the the subviews created in a storyboard. In the storyboard, I have a view, and inside a Vertical StackView, which has constraint to fill the full screen, distribution "Equal spacing". Inside of the Vertical Stack View, I have 3 horizontal stack views, with constraint height = 100, and trailing and leading space : 0 from superview. The distribution is "equal spacing" too. In each horizontal stack view, I have two views, with

Animate hidden property on UILabels in UIStackView causes different animations

折月煮酒 提交于 2019-12-07 06:33:35
问题 UIStackView makes it really easy to create a nice animation using the hidden property of a UIView. I have two UIStackViews each with UILabels in the arrangedSubviews and when I add a new UILabel to a UIStackView , it should present it with an animation of the label appearing at the correct index, pushing the labels above and below it. This effect is very easy to do using UIStackViews : descriptionLabel.hidden = true let count = descriptionStack.arrangedSubviews.count descriptionStack

UIStackView and multi-line labels in a UITableViewCell

我与影子孤独终老i 提交于 2019-12-07 06:09:09
问题 I want to have a custom UITableViewCell with a number of vertically stacked UILabel s all of which can contain text that wraps multiple lines. With the new UIStackView in iOS9 and the cell self-sizing mechanism I thought this would be straightforward, but I can't get it to work. I am using Xcode 7beta3. I created a simple test app. This is the setup in IB: The UIStackView is vertical with UIStackViewDistribution.Fill and UIStackViewAlignment.Fill but I have basically tried all the