去掉searchbar边框线

转载自   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];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值