viernes, 10 de marzo de 2017

iOS: Change constraint at runtime

Swift

let filteredConstraints = menuFooterCell?.contentView.constraints.filter { $0.identifier == "rightMargin" }
            if let yourConstraint = filteredConstraints?.first {
                yourConstraint.constant = tableView.frame.size.width - revealViewController().rearViewRevealWidth + 32
                menuFooterCell?.updateConstraints()
            }

More cleaver way:

public func set(constantValue constant: CGFloat, toConstraintNamed name: String) {
       
        let filteredConstraints = self.constraints.filter { $0.identifier == name }
        if let yourConstraint = filteredConstraints.first {
            yourConstraint.constant = constant
            self.updateConstraints()
        }
    }

No hay comentarios:

Publicar un comentario