tôi mới bắt đầu để phát triển iOS vì vậy tôi muốn chia sẻ toàn bộ thông tin tôi nhận được trong phần này.
Đầu tiên từ tài sản hình ảnh (images.xcassets) tạo tập hợp hình ảnh.
Theo Documentation đây là tất cả các kích thước cần tạo hình nền.
For iPhone 5:
640 x 1136
For iPhone 6:
750 x 1334 (@2x) for portrait
1334 x 750 (@2x) for landscape
For iPhone 6 Plus:
1242 x 2208 (@3x) for portrait
2208 x 1242 (@3x) for landscape
iPhone 4s (@2x)
640 x 960
iPad and iPad mini (@2x)
1536 x 2048 (portrait)
2048 x 1536 (landscape)
iPad 2 and iPad mini (@1x)
768 x 1024 (portrait)
1024 x 768 (landscape)
iPad Pro (@2x)
2048 x 2732 (portrait)
2732 x 2048 (landscape)
cuộc gọi hình ảnh nền chúng ta có thể gọi hình ảnh từ tài sản hình ảnh bằng cách sử dụng phương pháp này UIImage(named: "background")
đây là mã đầy đủ ví dụ
override func viewDidLoad() {
super.viewDidLoad()
assignbackground()
// Do any additional setup after loading the view.
}
func assignbackground(){
let background = UIImage(named: "background")
var imageView : UIImageView!
imageView = UIImageView(frame: view.bounds)
imageView.contentMode = UIViewContentMode.ScaleAspectFill
imageView.clipsToBounds = true
imageView.image = background
imageView.center = view.center
view.addSubview(imageView)
self.view.sendSubviewToBack(imageView)
}
Nguồn
2016-03-30 13:13:25
Bạn đang tìm kiếm [UIColor.colorWithPatternImage] (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIColor_Class/index.html#// apple_ref/occ/clm/UIColor/colorWithPatternImage :)? Thông tin thêm về hình nền cho UIView [ở đây] (http://beageek.biz/how-to-set-background-image-uiview/) – Xenyal