gpt4 book ai didi

ios - 以编程方式设置文本时,UITextField 占位符在 UI​​TextField.text 后面显示有阴影。为什么?

转载 作者:行者123 更新时间:2023-11-29 05:48:23 24 4
gpt4 key购买 nike

我正在设置 UITextField占位符的文本使用:

textField.placeholder = "placeholder"

然后,因为我正在使用 UIPickerView作为我的inputView ,当选择选择器 View 元素时,我更新 placeholder通过这样做textField.placeholder = nil并制作textField.text = "pickerViewValue" 。但占位符不清晰,文本后面有轻微的阴影,如下所示:

https://imgur.com/a/sMHvEje

(你必须看得非常近才能看到它。你会看到它在较暗的 L 后面非常微弱地写着“尺寸”)。

我尝试设置文本和 attributedText作为占位符而不是使用占位符属性,但每当我这样做时,第一个值设置为文本或 attributedText就像占位符文本一样保留在后台。我尝试将所有这些属性设置为 nil 和“​​”。没有骰子。想知道有没有人遇到过类似的问题。

格式化代码时遇到问题,所以这里有一个粘贴箱:

https://pastebin.com/pqmtaBeG

重要的内容在configure、updatePickerViews 和extensions 中。产品 View

let toolBar = UIToolbar()
toolBar.barStyle = .default
toolBar.isTranslucent = true
toolBar.tintColor = globalAppleBlue
toolBar.sizeToFit()

let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)

let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.plain, target: self, action: #selector(donePickerViewButtonTapped(_:)))
doneButton.setTitleTextAttributes([
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18)], for: .normal)

toolBar.setItems([spaceButton, doneButton], animated: false)
toolBar.isUserInteractionEnabled = true

let textField = VoraTextField(leftPadding: globalPadding * 1.5, rightPadding: 0.0)
textField.backgroundColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 0.9)

textField.placeholder = option.name.capitalized

let imageView = UIImageView(image: UIImage(named: "right-angle"))
imageView.contentMode = .scaleAspectFit

textField.rightView = imageView
textField.rightViewMode = .always
textField.font = UIFont.boldSystemFont(ofSize: 16)
textField.textColor = .black
textField.delegate = self

textField.inputAccessoryView = toolBar

let pickerView = UIPickerView()
self.pickerViewArray.append(pickerView)
pickerView.showsSelectionIndicator = true
pickerView.backgroundColor = .white
textField.inputView = pickerView
textField.borderStyle = .roundedRect

pickerView.delegate = self

最佳答案

我不太确定导致问题的原因,但作为解决方法,请尝试在文本字段中添加纯色背景色。

UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 1) // changed alpha to 1

当然,使用这个值,颜色会更深。

关于ios - 以编程方式设置文本时,UITextField 占位符在 UI​​TextField.text 后面显示有阴影。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55930720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com