注意:屏幕截图取自早期版本的iOS
码:
override func viewWillAppear(animated: Bool) {
// Creates image of the Button
let imageCameraButton: UIImage! = UIImage(named: "cameraIcon")
// Creates a Button
let cameraButton = UIButton(type: .Custom)
// Sets width and height to the Button
cameraButton.frame = CGRectMake(0.0, 0.0, imageCameraButton.size.width, imageCameraButton.size.height);
// Sets image to the Button
cameraButton.setBackgroundImage(imageCameraButton, forState: .Normal)
// Sets the center of the Button to the center of the TabBar
cameraButton.center = self.tabBar.center
// Sets an action to the Button
cameraButton.addTarget(self, action: "doSomething", forControlEvents: …Run Code Online (Sandbox Code Playgroud) 苹果说:
根据设备和方向,系统会显示常规或紧凑的标签栏。您的应用应包含两种尺寸的自定义标签栏图标。
不幸的是,他们未能指定您何时获得哪个。
此外,我可能会包含两种尺寸的图像,但系统会自动在它们之间切换(如何?)还是我必须自己做?