小编jan*_*son的帖子

可以修改UISearchbar TextField的高度吗?

我正在测试我的用户界面,我觉得搜索栏有点太狭隘了.我还想确保视力较差或手动灵巧较差的人在提出他们想要的界面方面没有任何问题.

所以,我想做的是调整UITextfield内部的高度UISearchbar.

我尝试过:1.在Storyboard中,添加UISearchbar高度约束 - 结果:搜索栏大小增加,但UITextField内部保持不变.

  1. 访问UITextField内部UISearchbar并修改其高度 - 结果:控制台输出显示参数已修改,但在屏幕上,UITextField高度保持不变.

注意 - 我可以修改UITextField使用方法2的其他参数,并且更改会反映在屏幕上,所以我知道我正在使用UITextField

方法2的代码,放在UISearchbar所在的ViewController的viewDidLoad()中:

for tempView in (self.roomInfoSearchBar.subviews[0] as! UIView).subviews as! [UIView]
{
  if let tV = tempView as? UITextField
  {
    var currentFrameRect = tV.frame
    currentFrameRect.size.height = 80
    //tV.layer.backgroundColor = UIColor.blueColor().CGColor  //This works fine
    //tV.layer.cornerRadius = 5  //This works fine
    //tV.font = UIFont(name: "Courier", size: 40)  //This works fine
    println(tV.frame.height)  //console output:0.0
    tV.frame = currentFrameRect …
Run Code Online (Sandbox Code Playgroud)

uisearchbar autolayout swift

35
推荐指数
5
解决办法
2万
查看次数

标签 统计

autolayout ×1

swift ×1

uisearchbar ×1