nslayoutconstraint

Add UISLider with Autolayout programmatically

百般思念 提交于 2019-12-05 22:21:45
I'm trying to add a UISlider to my view programmatically including constraints so that its width adapts to the whole screen width. This is what I got so far: //2 Add UISlider self.slider = [[UISlider alloc] init]; [self.view addSubview:self.slider]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.slider attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.slider attribute:NSLayoutAttributeRight relatedBy

Can you enter a constraint value with decimal in IB?

无人久伴 提交于 2019-12-05 15:57:32
问题 Here is to hoping it is a simple setting. I cannot enter a constraint value with decimals in IB. Whenever I enter a value with decimals and press enter, the system rounds it! I don't have this problem when creating constraints in code. Only in IB. Is there a way? 回答1: Yes, you can. Enter the value with a "f" postfix like this: Click Priority. notice how the effective constraint value changes to 0.5: Hit ESC 回答2: It has to be done programmatically, I believe. As of Xcode 6.3, constraint

Trailing and Leading constraints in Swift programmatically (NSLayoutConstraints)

狂风中的少年 提交于 2019-12-05 14:28:25
问题 I'm adding from a xib a view into my ViewController. Then I'm putting its constraints to actually fit it override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) ... ... view!.addSubview(gamePreview) gamePreview.translatesAutoresizingMaskIntoConstraints = false if #available(iOS 9.0, *) { // Pin the leading edge of myView to the margin's leading edge gamePreview.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true //Pin the trailing edge of myView to the

Why WKWebView doesn't display videos? - Swift 3

孤人 提交于 2019-12-05 13:28:55
I successfully added a WKWebView programmatically In a viewController (in viewDidLoad() ). When loading a url that contains a video it appears fine, but when I try to tap on it (playing it), I cannot see it, but the audio works fine. The weird thing is I created a new project just to make sure it should works fine and it did, I copied the same exact code the webView displayed the video as it should. It was working fine before converting to Swift 3. This is how it looks when tapping on the video: Before tapping: After Tapping: I also tried another web page: Before tapping: After Tapping (Note

What are gray constraints in Xcode view hierarchy debug view?

孤街浪徒 提交于 2019-12-05 12:28:33
问题 I know what the solid ones are: I created them myself. What about the gray ones? Implicit, maybe via size-to-fit? The gray height conflicts with the solid height. Where do the gray ones come from? 回答1: You are inspecting an object such as a label that has an intrinsic content size. The intrinsic content size generates height and width constraints; that's what intrinsic content size is . The constraints in gray are showing you the constraints that the intrinsic content size generates. If you

Deactive NSLayoutConstraint iOS7

老子叫甜甜 提交于 2019-12-05 11:48:41
I'm developing an app with a target of iOS7, and I get the following error when I deploy the app to an iPhone 4. [NSLayoutConstraint setActive:]: unrecognized selector sent to instance I looked into this and it turns out that setActive was introduced in iOS8. Question is, what is the alternative to setActive for constraints, circa iOS7? I need to manipulate the constraints programmatically and can't seem to find the answer anywhere. Another way to do this would be to add/remove the constraint from the view: [myView addConstraint:constraint]; [myView removeConstraint:constraint]; This has been

Catch UIViewAlertForUnsatisfiableConstraints in production

末鹿安然 提交于 2019-12-05 11:06:09
问题 Is it possible to catch autolayout constraint ambiguities in production – the equivalent of a UIViewAlertForUnsatisfiableConstraints breakpoint but for production apps? My goal would be to add a global handler that would report such errors to a logging system. 回答1: The symbol UIViewAlertForUnsatisfiableConstraints actually is a function : _UIViewAlertForUnsatisfiableConstraints(NSLayoutConstraint* unsatisfiableConstraint, NSArray<NSLayoutConstraint*>* allConstraints) . It is private, so you

NSLayoutConstraint constant not updating after setting

岁酱吖の 提交于 2019-12-05 09:38:43
问题 I have a UIView subclass with a corresponding xib file. In my xib I have a NSLayoutConstraint property which I'm trying to animate. I have an animateIn method. The problem is that only the animateIn method works. When I try to update the constant again it simply stays at the previous value. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *horizontalConstraint; I'm trying to update the constant after a button press. But the constant doesn't seem to update after setting. It still logs 0

How to write NSConstraint visual format language by including another button's width plus a constant

允我心安 提交于 2019-12-05 09:35:34
In the docs about the visual format language for NSLayoutConstraint there is an example where you specify button1 is equal in width to button2: [button1(==button2)] my question: is there a way to make button1 equal to button 2's with + a constant.. I tried: [button1(==button2+10)] and [button1(==(button2+10))] and both failed.. here is an error example: A predicate on a view's thickness must end with ')' and the view must end with ']' V:[tagWrapper(==tagButton+10)] ^' (I obviously know you can do this by doing an NSStringWithFormat and simply filling in the variable in question.. but that

Autolayout confusion: Constraints for ScrollView with WebView and Header/Footer Views

无人久伴 提交于 2019-12-05 08:40:26
To illustrate my problem, I created the following graphic: The black border around the red square is supposed to be the iPhone screen. Inside, we have in red a UIScrollView , which is taller than the screen. It is, in fact, as tall as a UIWebView , displayed above in yellow. The UIWebView is a subview of the UIScrollView , with scrolling disabled. Further more, we have two blue views, which I like to call the header and footer views. They are also subviews of the UIScrollView , but outside of the scrollable bounds. My problem now is : How do I configure the auto layout constraints for this? I