Coder Social home page Coder Social logo

constraintlib's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

constraintlib's Issues

Pin not working properly for UILabel

Hi, I am experimenting some unexpected behaviour with .pin function, I am not sure if I missed something.

I have the code snippet bellow. However, my fonts is being added but it is not visible.

        label = UILabel()
        label.text = textLabel
        label.textAlignment = .center
        label.textColor = UIColor.green
        label.font = UIFont(name: fontName, size: self.bounds.height)
        label.adjustsFontSizeToFitWidth = true
        label.baselineAdjustment = .alignCenters
        self.addSubview(label)
        
        label.pin([.top, .left, .width, .height])

Then, when I changed the Constraints to the native one, it shows up.

        label = UILabel()
        label.text = textLabel
        label.textAlignment = .center
        label.textColor = UIColor.green
        label.font = UIFont(name: fontName, size: self.bounds.height)
        label.translatesAutoresizingMaskIntoConstraints = false
        label.adjustsFontSizeToFitWidth = true
        label.baselineAdjustment = .alignCenters
        self.addSubview(label)
        
//        label.pin([.top, .left, .width, .height])
        
        NSLayoutConstraint(
            item: label,
            attribute: .top,
            relatedBy: .equal,
            toItem: self,
            attribute: .top,
            multiplier: 1.0,
            constant: 0
            ).isActive = true
        
        NSLayoutConstraint(
            item: label,
            attribute: .left,
            relatedBy: .equal,
            toItem: self,
            attribute: .left,
            multiplier: 1.0,
            constant: 0
            ).isActive = true
        
        NSLayoutConstraint(
            item: label,
            attribute: .height,
            relatedBy: .equal,
            toItem: self,
            attribute: .height,
            multiplier: 1.0,
            constant: 0
            ).isActive = true
        
        NSLayoutConstraint(
            item: label,
            attribute: .width,
            relatedBy: .equal,
            toItem: self,
            attribute: .width,
            multiplier: 1.0,
            constant: 0
            ).isActive = true

Help using constraints with topLayoutGuide

I am trying to use self.topLayoutGuide to position my widget. But I can't compile. It says

/Users/eduardoj/Qwantech/Blupper_Iphone/Blupper/Blupper/BlupRevealVC.swift:28:21: Type of expression is ambiguous without more context

Here is my code:

let newView = UIView()
mainStack.addSubview(newView)
newView.pin([.top: self.topLayoutGuide, .left:0.0, .height:100.0, .width:100.0])
newView.backgroundColor = UIColor.red

I already tried:

newView.pin([.top: self.topLayoutGuide.length, .left:0.0, .height:100.0, .width:100.0])
and

newView.pin([.topTo(self.topLayoutGuide): 0, .left:0.0, .height:100.0, .width:100.0])
but didn't work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.