感謝所有幫助:)!使用iboutlet集合修復它並在viewDidLoad上添加適當的東西如何將屬性添加到UIButton?
我試圖給鍵盤按鍵添加屬性,如layer.shadowColor
或layer.shadowRadius
。 我得到了一個錯誤
'Value of type '(UIButton)' ->() has no member 'layer'
如何解決這個問題?
這是我的代碼keyboardViewController.swift
進口的UIKit
類KeyboardViewController:UIInputViewController {VAR newKeyboardView:UIView的!
@IBAction func keyPressed(sender: UIButton) {
}
@IBOutlet var nextKeyboardButton: UIButton!
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
}
override func viewDidLoad() {
super.viewDidLoad()
loadInterface()
}
func loadInterface() {
// load the nib file
let keyboardNib = UINib(nibName: "newKeyboard", bundle: nil)
// instantiate the view
newKeyboardView = keyboardNib.instantiateWithOwner(self, options: nil)[0] as! UIView
// add the interface to the main view
view.addSubview(newKeyboardView)
// copy the background color
view.backgroundColor = newKeyboardView.backgroundColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated
}
override func textWillChange(textInput: UITextInput?) {
// The app is about to change the document's contents. Perform any preparation here.
}
override func textDidChange(textInput: UITextInput?) {
// The app has just changed the document's contents, the document context has been updated.
var textColor: UIColor
let proxy = self.textDocumentProxy
if proxy.keyboardAppearance == UIKeyboardAppearance.Dark {
textColor = UIColor.whiteColor()
} else {
textColor = UIColor.blackColor()
}
self.nextKeyboardButton.setTitleColor(textColor, forState: .Normal)
}
}
你可以顯示代碼嗎? – good4pc
@IBAction func keyPressed(sender:UIButton){ }我添加了一些按鈕,並希望爲按鈕添加陰影。像使用layer.shadowColor –
裏面keyPressed(發件人:UIButton),編寫代碼添加陰影,例如我已添加一些代碼添加邊框顏色.. sender.layer.borderColor = UIColor.redColor()。CGColor sender.layer .borderWidth = 2.0希望它有幫助。 – good4pc