Currently using:
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png")!)
But the problem is that it repeats both vertically and horizontally. I'm trying to keep it repeating horizontally while stretching vertically to fit the screen.
Subclass UIView call it something like BackgroundImageView or something it override drawInRect thusly:
import UIKit
@IBDesignable
class BackgroundImageView: UIView {
@IBInspectable var backgroundImage:UIImage?{
didSet{
self.setNeedsDisplay()
}
}
override func drawRect(rect: CGRect) {
var i:CGFloat = 0.0
if backgroundImage != nil
{
while (i*backgroundImage!.size.width)<self.bounds.size.width
{
backgroundImage!.drawInRect(CGRect(x: i*backgroundImage!.size.width, y: 0.0, width: backgroundImage!.size.width, height: self.bounds.size.height))
i+=1.0
}
}
}
}
Drag out a UIView in IB change its class to BackgroundImageView and set the backgroundImage to background.png.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With