Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift ways to setup constraints

//https://stackoverflow.com/a/26181982/13171606
//There are multiple ways to add contraints, please open Link for almost ecery type of constraint

override func viewDidLoad() {
    let newView = UIView()
    newView.backgroundColor = UIColor.red
  
    view.addSubview(newView)
    
    newView.translatesAutoresizingMaskIntoConstraints = false//compulsory
    newView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    newView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    newView.widthAnchor.constraint(equalToConstant: 100).isActive = true
    newView.heightAnchor.constraint(equalToConstant: 100).isActive = true
}

Comment

swift constraints


 - firstView.coverWholeSuperview()
 - firstView.constraints(size: CGSize(width: 44, height: 44), centerX: view.centerXAnchor, centerY: view.centerXAnchor)
 - firstView.constraints(top: view.topAnchor, 
                         leading: secondView.leadingAnchor, 
                         bottom: view.bottomAnchor, 
                         trailing: secondView.trailingAnchor, 
                         padding: UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12))

Comment

Type Constraints in Swift Generics

func addition<T: Numeric>(num1: T, num2: T) {
  ...
}
Comment

Type Constraints Swift

//create a generic function with type constraint
func addition<T: Numeric>(num1: T, num2: T) {

  print("Sum:", num1 + num2)
}

// pass Int value
addition(num1: 5, num2: 10)

// pass Double value
addition(num1: 5.5, num2: 10.8)
Comment

PREVIOUS NEXT
Code Example
Swift :: swift from 1 to 01 
Swift :: Swift for Loop with where Clause 
Swift :: swift disable modal dismiss swift 
Swift :: Swift nested if Statement 
Swift :: swift multiple return values 
Swift :: compactMap 
Swift :: Swift Computed Property In Extension 
Swift :: var i = 2 repeat { i *= i * 2 } while i < 100 print(i) 
Swift :: swift variables 
Swift :: Swift Nested Ternary Operators 
Swift :: Swift Code Reusability 
Swift :: swift open messages app 
Swift :: array of button listeners swift 
Swift :: change textview link color swift 
Swift :: Swift guard with multiple conditions 
Swift :: how to declare populated dictionary in swift 
Swift :: Memberwise Initializer Swift 
Swift :: no module like realmswift 
Swift :: Struct Instances Swift 
Swift :: swift array to data 
Swift :: swift get last element of array 
Ruby :: rails mimemagic issue 
Ruby :: microsoft office 2016 txt file activator 
Ruby :: ruby reference a file in a gem 
Ruby :: unix timestamp to date time rails 
Ruby :: rails find_by order 
Ruby :: button submit rails with font awesome 
Ruby :: ruby find method 
Ruby :: rails logger info 
Ruby :: rails parse boolean 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =