gpt4 book ai didi

ios - 如何在 UIsearchbar iOS swift 中为文本字段添加自定义图像

转载 作者:行者123 更新时间:2023-11-29 01:35:13 25 4
gpt4 key购买 nike

我正在尝试创建自定义搜索栏。我想为搜索栏中的文本字段添加自定义图像。我将搜索栏样式设置为最小。我使用以下代码更改背景图像。它不太合适。此导出以编程方式添加

let srchtextfld: UITextField = srchbr.valueForKey("searchField") as! UITextField

srchtextfld.layer.backgroundColor = UIColor(patternImage: UIImage(named: "Rounded Rectangle 1 copy 3.png")!).CGColor

我正在获取下图

enter image description here

我想添加这种类型的图像作为背景

enter image description here

感谢任何帮助

最佳答案

如果你想设置背景图片那么属性是背景而不是背景颜色见docs .所以你喜欢这样

srchtextfld.background  = UIImage(named: "Rounded Rectangle 1 copy 3.png")!

还记得

When set, the image referred to by this property replaces the standard appearance controlled by the borderStyle property. Background images are drawn in the border rectangle portion of the text field. Images you use for the text field’s background should be able to stretch to fit.

加上

UITextBorderStyleRoundedRect, custom background images are ignored.

关于ios - 如何在 UIsearchbar iOS swift 中为文本字段添加自定义图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33034402/

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