简体   繁体   English

首次使用前UISearchBar尺寸不一致?

[英]Inconsistent UISearchBar sizing before first use?

For a reason that is unclear, my UISearchBar resizes itself to a different size after the first search. 由于一个不清楚的原因,我的UISearchBar在第一次搜索后将其自身调整为不同的大小。 There is nothing special about this search bar. 这个搜索栏没有什么特别之处。 It's based off of the example on the Apple IOS Library and uses a searchDisplayController, with virtually no customization. 它基于Apple IOS库上的示例,并使用searchDisplayController,几乎没有自定义。

Before: 之前:

在搜索之前

After: 后:

搜索后

How can I set the size to what it is in the second screenshot when the view loads? 当视图加载时,如何将大小设置为第二个屏幕截图中的大小?

If you're using a nib, you can just check "Shows Cancel Button" from the Search bar options in your attributes. 如果您正在使用笔尖,则可以从属性的“搜索栏”选项中选中“显示取消按钮”。

If you're doing it programmatically, do some subclassing with the UISearchBar and override this method: 如果您是以编程方式执行此操作,请使用UISearchBar进行一些子类化并覆盖此方法:

-(void)layoutSubviews{
    [super layoutSubviews];
    [self setShowsCancelButton:YES animated:NO];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM