转载自 http://codego.net/361893/
使用第五个解决问题
1. 我通过添加一个子视图到seekbar的视图堆栈解决了这个问题。
CGRect rect = self.searchBar.frame;
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, rect.size.height-2,rect.size.width, 2)];
lineView.backgroundColor = [UIColor whiteColor];
[self.searchBar addSubview:lineView];
self.searchBar是我的控制器类的指针的UISearchBar。
2. 该tableHeaderView设置为
nil
把你的前
UISearchBar
那里。 如果这样没有帮助,试图掩盖它。首先你的seekbar添加到一个通用的,适当大小的
UIView
(例如,“包装”)作为一个子视图,然后
CGRect frame = wrapper.frame;
CGRect lineFrame = CGRectMake(0,frame.size.height-1,frame.size.width, 1);
UIView *line = [[UIView alloc] initWithFrame:lineFrame];
line.backgroundColor = [UIColor whiteColor]; // or whatever your background is
[wrapper addSubView:line];
[line release];
然后将其添加到tableHeaderView。
self.tableView.tableHeaderView = wrapper;
[wrapper release];
3. sBar.layer.borderWidth=1; sBar.layer.borderColor=[[的UIColor lightGrayColor] CGColor];
4. 警告。这是一个hacker。想知道一个更好的,更正式的方式。 你的小马调试器来找出其中的子视图的层次结构是。我觉得你看到的是一个private的UIImageView称为“分隔符”
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
for (UIView* view in self.searchBar.subviews) {
if (view.frame.size.height == 1 && [view isKindOfClass:[UIImageView class]]) {
view.alpha = 0;
break;
}
}
}
5. 这个问题已经得到解决,但也许我的解决方案可以帮助别人。我有一个类似的问题 CodeGo.net,但我是想去掉1px的顶部边框。 如果子类
UISearchBar
你可以覆盖这个样子。
- (void)setFrame:(CGRect)frame {
frame.origin.y = -1.0f;
[super setFrame:frame];
self.clipsToBounds = YES;
self.searchFieldBackgroundPositionAdjustment = UIOffsetMake(0, 1.0f);
}
或者,如果您想解决的底部像素,你可以做这样的,(未经测试)。
- (void)setFrame:(CGRect)frame {
frame.origin.y = 1.0f;
[super setFrame:frame];
self.clipsToBounds = YES;
self.searchFieldBackgroundPositionAdjustment = UIOffsetMake(0, -1.0f);
}
只为榜样的简便性是
clipsToBounds
和
searchFieldBackgroundPositionAdjustment
在
setFrame
。 还
searchFieldBackgroundPositionAdjustment
只需要重新中心的seekbar。 更新 事实证明,该
tableView
将从转向更新的1px的
origin.y
而seekbar处于活动状态。感觉有点怪怪的。我意识到,解决方案很简单,只要设定,
self.clipsToBounds = YES;
6. 您
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"someImage.png"]forState:UIControlStateNormal];