【问题标题】:UITextField Height not changing when set as inputAccessoryView for another UITextField设置为另一个 UITextField 的 inputAccessoryView 时,UITextField 高度不会改变
【发布时间】:2014-07-26 13:56:23
【问题描述】:
var textF2 = UITextField()
textF2.borderStyle = UITextBorderStyle.None
textF2.frame.size = CGSizeMake(200, 200)
textF2.text = self.textField.text
textF2.backgroundColor = UIColor.whiteColor()

self.textField.inputAccessoryView = textF2

textF2 的高度拒绝正确设置,至少在其外观方面。

println(textF2.frame.size.height)

给我 200 的新值,但它不会以这种方式出现在模拟器中。

inputAccessoryView 是否会导致与设置高度相关的问题?

var textF2 = UITextField()
textF2.borderStyle = UITextBorderStyle.None
textF2.frame = CGRectMake(50, 50, 200, 200)
textF2.text = self.textField.text
textF2.backgroundColor = UIColor.whiteColor()
self.view.addSubview(textF2)

确实给了我适当的外表,所以

self.textField.inputAccessoryView = textF2

是问题所在。有人知道为什么吗?

【问题讨论】:

  • 不,看我的代码,不一样。我采用相同的建议。
  • 编译器会给你警告/错误吗?
  • 不,XCode 只是从该 println 写入 200.0
  • 你在使用自动布局吗?

标签: ios objective-c swift


【解决方案1】:

inputAccessoryView 只是下面的普通UIView,因此要正确定位它,您应该始终设置frame,仅设置大小将无效。

另外,请记住,在对象成为第一响应者之后,对 inputAccessoryView 的任何更改都应在调用 reloadInputViews 之后进行,否则它们将不会产生任何影响。

【讨论】:

  • 感谢reloadInputViews 的提醒。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多