代码如下:
let page = UIView() page.frame = self.view.bounds //直接设置颜色 page.backgroundColor = UIColor.greenColor() //设置16进制的颜色 page.backgroundColor = UIColor(red: 0x37/255, green: 0xba/255, blue: 0x46/255, alpha: 1) //设置背景图片(如果图片太小,会自动平铺) page.backgroundColor = UIColor.init(patternImage: UIImage(named: "11.jpg")!) self.view.addSubview(page)