【问题标题】:Remove the dark Line at the bottom of Navigationbar/Searchbar移除导航栏/搜索栏底部的黑线
【发布时间】:2012-12-06 14:23:17
【问题描述】:

我想做一个干净的白色设计。所以,我将tintColor属性设置为whiteColor,但是UINavigationBarUISearchBar下面有这些暗线。

有人知道如何去除暗线或如何改变颜色吗?

【问题讨论】:

    标签: ios xcode uinavigationbar uisearchbar


    【解决方案1】:

    按类别向 UIImage 添加方法

    + (UIImage *)imageWithColor:(UIColor *)color {
        CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return theImage;
    }
    

    然后设置

    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor whiteColor]]];
    

    【讨论】:

    • 或者 self.navigationController.navigationBar.shadowImage = [UIImage new];
    • @Caroline 如果在故事板中,如何删除导航栏底线?
    【解决方案2】:

    这是我所做的,并且似乎有效,这是此链接的进一步发展。我将显式宽度声明更改为动态声明,这样无论您是否更改视图大小,它都会是视图的大小:

    UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, self.view.frame.size.width, 1)];
    [overlayView setBackgroundColor:[UIColor whiteColor]];
    [navBar addSubview:overlayView]; // navBar is your UINavigationBar instance
    [overlayView release];
    

    我在这里找到了这些东西: How to remove UINavigatonItem's border line

    【讨论】:

      【解决方案3】:

      从 iOS 7 开始,UINavigationBar 有一个 shadowImage 属性,您可以将其设置为 nil。

      【讨论】:

        猜你喜欢
        • 2013-10-03
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        • 2022-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多