我的iOS應用程序已經有這兩個按鈕現在月:它們在IB,但在viewDidLoad中添加如何刪除不需要的按鈕陰影
我圓邊角和更新的背景色。
今天我添加了一個功能到一個textField是在同一個視圖。現在,當VC負載/給出的觀點似乎和,四分之一秒的延遲後,陰影出現在按鈕背後:
我沒有在屬性檢查器中改變一個單一的東西。我也沒有改變四捨五入按鈕的代碼。自問題開始以來,我現在添加了明確的無影子代碼,並確保檢查器設置爲清除陰影。
func roundBut (Type: UIView) {
Type.layer.cornerRadius = 6
Type.layer.borderWidth = 0.0
Type.layer.masksToBounds = true
Type.layer.borderColor = UIColor.whiteColor().CGColor
Type.layer.shadowOpacity = 0.0
Type.layer.shadowColor = nil
Type.layer.shadowRadius = 0.0
}
最後一個奇怪的是,如果我點擊進入文本字段,陰影就會消失。
更多的代碼,如要求:
下面是這個包括viewDidLoad中,該圓角的功能,併爲文本字段和文本視圖的代碼相關的代碼,幾乎每一個位:
override func viewDidLoad() {
super.viewDidLoad()
//If user is editing a cell, check...
if passingEdit == true {
//If passed an 'Add New' cell: It clears that text
if namePassed == nil && descPassed == "Add new" {
txtDesc.text = ""
addSave.setTitle("Add", forState: UIControlState.Normal)
action.hidden = true
actionsBox.hidden = true
passingEdit = false
}
else {
//Otherwise: Fill both fields with cell's content
txtTask.text = namePassed
txtDesc.text = descPassed
action.hidden = true //Becasue action box will be visible
addSave.setTitle("Update", forState: UIControlState.Normal)
}
}
else {
txtTask.becomeFirstResponder()
addSave.setTitle("Add", forState: UIControlState.Normal)
action.hidden = true
actionsBox.hidden = true
}
//If user hasn't added details: Show Placeholder
if txtDesc.text.isEmpty {
txtDesc.text = "Tap here to add details."
txtDesc.textColor = UIColor.lightGrayColor()
}
//Sets editor header text
switch (currentListEntity) {
case "TodayTask":
hdr_Txt.setTitle("Today", forState: UIControlState.Normal)
txtTask.attributedPlaceholder = NSAttributedString(string:"I need to...", attributes:[NSForegroundColorAttributeName: UIColor.lightGrayColor()])
move_TopBtn.setTitle("Add to 'Tomorrow'", forState: UIControlState.Normal)
move_TopBtn.backgroundColor = UIColor(red: 49/255.0, green: 82/255.0, blue: 172/255.0, alpha: 1.0)
case "TomTask":
hdr_Txt.setTitle("Tomorrow", forState: UIControlState.Normal)
txtTask.attributedPlaceholder = NSAttributedString(string:"I need to...", attributes:[NSForegroundColorAttributeName: UIColor.lightGrayColor()])
move_TopBtn.setTitle("Add to 'Today'", forState: UIControlState.Normal)
move_TopBtn.backgroundColor = UIColor(red: 0/255.0, green: 128/255.0, blue: 0/255.0, alpha: 1.0)
case "TBDTask":
hdr_Txt.setTitle("Do Later", forState: UIControlState.Normal)
txtTask.attributedPlaceholder = NSAttributedString(string:"At some point, I need to...", attributes:[NSForegroundColorAttributeName: UIColor.lightGrayColor()])
case "FinTask":
//This won't likely run, as "Fin" does not have an add button
hdr_Txt.setTitle("Done", forState: UIControlState.Normal)
default:
//Should run when user's current location is the Life Lists
hdr_Txt.setTitle("List Item", forState: UIControlState.Normal)
txtTask.attributedPlaceholder = NSAttributedString(string:"Name of List Item", attributes:[NSForegroundColorAttributeName: UIColor.lightGrayColor()])
move_TopBtn.setTitle("Add to 'Today'", forState: UIControlState.Normal)
move_TopBtn.backgroundColor = UIColor(red: 0/255.0, green: 128/255.0, blue: 0/255.0, alpha: 1.0)
move_BotBtn.setTitle("Add to 'Tomorrow'", forState: UIControlState.Normal)
move_BotBtn.backgroundColor = UIColor(red: 49/255.0, green: 82/255.0, blue: 172/255.0, alpha: 1.0)
}
//Round check/delete views
makeCircle(deleteBtn)
makeCircle(doneBtn)
//Round corners of rectangles
roundBut(move_TopBtn)
roundBut(move_BotBtn)
move_TopBtn.layer.shadowColor = UIColor.clearColor().CGColor
move_TopBtn.layer.shadowRadius = 0.0
print("editorVC viewDidLoad ran")
}//End of viewDidLoad
//*****************************
//Setup - Reference Functions
//*****************************
//Round contentView
func roundBut (Type: UIView) {
Type.layer.cornerRadius = 6
Type.layer.borderWidth = 0.0
Type.layer.masksToBounds = true
Type.layer.borderColor = UIColor.whiteColor().CGColor
Type.layer.shadowOpacity = 0.0
Type.layer.shadowColor = nil
Type.layer.shadowRadius = 0.0
}
func makeCircle (viewToRound: UIButton) {
viewToRound.layer.cornerRadius = viewToRound.frame.size.width/2
viewToRound.layer.borderWidth = 0.0
viewToRound.layer.masksToBounds = true
}
//***** ----- ***** ------ ***** ----- ***** ----- *****
//Functionality
//***** ----- ***** ------ ***** ----- ***** ----- *****
func textFieldDidBeginEditing(textField: UITextField) {
if txtTask.text != "" {
action.hidden = false
}
}
//Dismisses keyboard upon tapping the return key
func textFieldShouldReturn(textField: UITextField) -> Bool{
textField.resignFirstResponder()
return true
}
//Dismisses keyboard upon touch outside text boxes
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
action.hidden = true
}
func textViewDidBeginEditing (textView: UITextView) {
if textView.textColor == UIColor.lightGrayColor() {
textView.text = nil
textView.textColor = UIColor.whiteColor()
}
action.hidden = false
}
func textViewDidEndEditing(textView: UITextView) {
if textView.text.isEmpty {
txtDesc.text = "Tap here to add details."
textView.textColor = UIColor.lightGrayColor()
}
}
最後說明:深灰色背景是視覺效果視圖。不知道這是否重要。
任何人有任何想法?
您是否嘗試明確禁用textField上的陰影?我的想法是,也許有一些錯誤與masksToBounds它不影響子視圖陰影。 – Sidetalker
你應該發佈更多的代碼。你添加的功能是什麼?這個代碼在哪裏被調用? – beyowulf
@beyowulf - 添加代碼 –