Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在导航栏和UISearchBar之间添加间距?_Ios_Objective C_Uisearchbar - Fatal编程技术网

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

Ios 如何在导航栏和UISearchBar之间添加间距?,ios,objective-c,uisearchbar,Ios,Objective C,Uisearchbar,我想在导航栏和UISearchBar之间添加一个进度条。我可以知道如何实现这一点吗?请帮忙。多谢各位 这是我在Cell.m中的当前代码 - (void)layoutSubviews { [super layoutSubviews]; CGRect barFrame = CGRectInset(self.searchBar.frame, 10.0f, 10.0f); self.searchBar.frame = barFrame; } 这是我在ViewControll

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

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

- (void)layoutSubviews
{
    [super layoutSubviews];

    CGRect barFrame = CGRectInset(self.searchBar.frame, 10.0f, 10.0f);
    self.searchBar.frame = barFrame;
}
这是我在ViewController.m中的当前代码 编辑后未反映在此代码中<代码>\u searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0,0,kScreenWidth,24)]


根据您的应用程序,有几个简单的选项供您选择。我认为基于您如何解释问题的最佳解决方案是将进度条包含到您的视图中,并确保它位于其他视图之上,同时将其定位在导航栏之下

_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 bringsubview tofront:\u valueProgress]

_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;
}