【发布时间】:2016-08-23 06:29:44
【问题描述】:
感谢所有帮助:)!使用 iboutlet 集合修复它并在 viewDidLoad 上添加属性
我正在尝试为layer.shadowColor 或layer.shadowRadius 等键盘键添加属性。
我有一个错误
'Value of type '(UIButton)' -> () has no member 'layer'
如何解决这个问题?
这是我的代码keyboardViewController.swift
导入 UIKit
类键盘视图控制器: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)
}
}
【问题讨论】:
-
你能显示代码吗?
-
@IBAction func keyPressed(sender: UIButton) { } 我添加了一些按钮并想为按钮添加阴影。像使用 layer.shadowColor
-
在 keyPressed(sender: UIButton) 内部,编写添加阴影的代码,例如我添加了一些用于添加边框颜色的代码.. sender.layer.borderColor = UIColor.redColor().CGColor sender。 layer.borderWidth = 2.0 希望有帮助。
-
出现错误。我上次得到的也是一样:c..'顺便说一句谢谢!
-
尝试输入'let button = sender as Button!'和 func keyPressed(sender: UIButton) 中的 'button.layer.....'
标签: ios swift uibutton quartz-core