how to set a background image as colorWithPatternImage in swift

Refer to the UIColor documentation. In Swift, you have to call a convenience initializer. This is because in Swift, all Objective-C class methods which return an instance of their class become convenience initializers. Here’s how it looks in Swift: self.view.backgroundColor = UIColor(patternImage: UIImage(named: “background.png”)) + (UIColor *)colorWithPatternImage:(UIImage *)image returns a UIColor instance, so it will … Read more

Assign xib to the UIView in Swift

for Swift 4 extension UIView { class func loadFromNibNamed(nibNamed: String, bundle: Bundle? = nil) -> UIView? { return UINib( nibName: nibNamed, bundle: bundle ).instantiate(withOwner: nil, options: nil)[0] as? UIView } } for Swift 3 You could create an extension on UIView: extension UIView { class func loadFromNibNamed(nibNamed: String, bundle: NSBundle? = nil) -> UIView? { … Read more

How do I change UIView Size?

This can be achieved in various methods in Swift 3.0 Worked on Latest version MAY- 2019 Directly assign the Height & Width values for a view: userView.frame.size.height = 0 userView.frame.size.width = 10 Assign the CGRect for the Frame userView.frame = CGRect(x:0, y: 0, width:0, height:0) Method Details: CGRect(x: point of X, y: point of Y, … Read more

UIView’s frame, bounds, center, origin, when to use what?

Marco’s answer above is correct, but just to expand on the question of “under what context”… frame – this is the property you most often use for normal iPhone applications. most controls will be laid out relative to the “containing” control so the frame.origin will directly correspond to where the control needs to display, and … Read more