如何在导航栏和UISearchBar之间添加间距?

时间:2018-06-11 03:49:08

标签: ios objective-c uisearchbar

我想在导航栏和UISearchBar之间添加一个进度条。我可以知道如何实现这个目标吗?请帮忙。谢谢。

enter image description here

这是我目前在Cell.m中的代码

_searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 24)];

以下是我在ViewController.m中的当前代码 编辑后没有在此代码中反映出来。 - (void)viewDidLoad { [super viewDidLoad]; _valueProgress = [[LDProgressView alloc] initWithFrame:CGRectMake(0,DCNaviH, ScreenW, 10.0f)]; _valueProgress.type = LDProgressSolid; _valueProgress.color = ThemeRedColor; _valueProgress.progress = 0.40; _valueProgress.flat = @YES; _valueProgress.showText = @NO; [self.view addSubview:_valueProgress]; } - (UISearchBar *)searchBar{ if (!_searchBar) { _searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 24)]; [_searchBar setBackgroundImage:[UIImage imageNamed:@"ic_searchBar_bgImage"]]; }]; } return _searchBar; }

build job: 'abc', 
    parameters: [
        string(name: 'build_number', value: String.valueOf(BUILD_NUMBER))
    ]

1 个答案:

答案 0 :(得分:0)

根据您的应用用户体验,有几个简单的选项。我认为根据您解释问题的方式为您提供的最佳解决方案是将进度条包含在您的视图中,并确保它位于导航栏下方的其他视图之上。

_valueProgress = [[LDProgressView alloc] init];
_valueProgress.translatesAutoresizingMaskIntoConstraints = NO;
_valueProgress.type = LDProgressSolid;
_valueProgress.color = ThemeRedColor;
_valueProgress.progress = 0.40;
_valueProgress.flat = @YES;
_valueProgress.showText = @NO;
[self.view addSubview:_valueProgress];
[_valueProgress.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].isActive = YES;
[_valueProgress.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].isActive = YES;
[_valueProgress.heightAnchor constraintEqualToConstant:10.0f].isActive = YES;

if (@available(iOS 11.0, *)) {
    [_valueProgress.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].isActive = YES;
} else {
    [_valueProgress.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].isActive = YES;
}

如果搜索栏已添加到进度条上方,您随后可以随时致电[self.view bringSubviewToFront:_valueProgress]