iOS searchBar底部黑线

本文介绍了多种方法来解决UISearchBar底部出现1px黑线的问题,包括通过添加子视图遮盖、调整tableHeaderView设置以及利用Swift代码进行样式定制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://codego.net/361893/ 来源地址

自定义的UISearchBar:试图摆脱1px的黑线的seekbar下方

iphone ios ipad uisearchbar
我的问题已经在标题中指定的是:我想摆脱黑线绘制在的UISearchBar的底部。任何想法? 下面是一个什么形象 更新: 我认为行是的UITableView的tableHeaderView的一部分。我仍然不知道如何删除它。

本文地址 :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];
    在iOS 5 +摆脱了线的。
    本文标题 :自定义的UISearchBar:试图摆脱1px的黑线的seekbar下方
    本文地址 :CodeGo.net/361893/
  7. RSO之间的flex和RED5。我可以创造,但不能读
  8. 在开关壳体的菜单使用字符串?
  9. 怎样才能得到一个SVG组元素的高度/宽度?
  10. 如何获得在MySQL表中的数据转换成Java JTable中?
  11. 如何设置WPF窗口的位置,桌面的右下角?
  12. 字符串从PHP脚本来闪
  13. 获取XML的CDATA节使用LINQ
  14. C#中:重写GetHashCode,这是什么代码呢?
  15. 如何将字节数组转换为位图
  16. 为什么它是一个坏主意,用“新”? [复制]

Copyright © 2014 CodeGo.net
http://codego.net/xinwen/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值