nslayoutanchor

Add multiplier to NSLayoutAnchor constraints in Swift

China☆狼群 提交于 2020-12-13 04:53:28
问题 Anchor constraints simplify adding constraints but the multiplier property available in storyboard does not seem to be available for all types of constraints. For example, as per the answer here, you can center a label in a view with: view.addSubview(loadingLabel) loadingLabel.translatesAutoresizingMaskIntoConstraints = false loadingLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true loadingLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

heightAnchor.constraint not change height of view

人盡茶涼 提交于 2020-07-09 16:25:47
问题 I use this code: func show(){ view.translatesAutoresizingMaskIntoConstraints = false view.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true view.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true view.heightAnchor.constraint(equalToConstant: view.frame.height - 300).isActive = true view.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true } func hide(){ view.translatesAutoresizingMaskIntoConstraints = false view

How to update anchor constraint in swift

我与影子孤独终老i 提交于 2020-03-05 03:31:49
问题 I would like to create a menu like android in iOS. I'm using layout constraints to setup constraints . I'm facing the issue when I'm trying to update the left constraint of an image on button click (It should animate to clicked button's position). Can anyone help me? It should support landscape and portrait. I don't want to user third party code and don't want to use the NSLayoutconstraint . Here is my code. class MenuViewController: UIViewController { var buttons: [UIButton] = [] var

How to set the NSLayoutAnchor to generate an centered subview with aspect ratio 1:1

ぃ、小莉子 提交于 2019-12-30 05:27:05
问题 It doesn't sound too difficult, but after hours of trying I couldn't get a proper solution. Problem: I want to set constraints (with class NSLayoutAnchor) to get a subview (colorImageView) beeing centered in the superview, with a aspect ratio of 1:1 AND always at the maximum size possible in a superview that sometimes has a width > height OR height > width. Example 1 : SuperViewSize = width : 80, height = 100 -> subview should get a height and width of 80 and centered at (40/50) Example 2 :

On iOS, what are the differences between margins, edge insets, content insets, alignment rects, layout margins, anchors…?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 12:06:13
There seem to be several different options/terms and people in the iOS community use with respect to layout (e.g. UIEdgeInsets is a type, but sometimes I hear/read "set the insets" or layout margins vs layout guides). I've always been able to find an option that works. But I'm never sure that I'm using the right tool for the job. Can someone help provide some clarity between these different aspects of layout and when to use each in the best way? Being the Bounty offerer...I'd say the majority of my confusion came from not properly understanding the UILayoutGuide class. That is key, but also

On iOS, what are the differences between margins, edge insets, content insets, alignment rects, layout margins, anchors…?

旧城冷巷雨未停 提交于 2019-11-26 15:53:59
问题 There seem to be several different options/terms and people in the iOS community use with respect to layout (e.g. UIEdgeInsets is a type, but sometimes I hear/read "set the insets" or layout margins vs layout guides). I've always been able to find an option that works. But I'm never sure that I'm using the right tool for the job. Can someone help provide some clarity between these different aspects of layout and when to use each in the best way? 回答1: Being the Bounty offerer...I'd say the