ios - 为导航栏创建一个粘性 View

标签 ios objective-c iphone swift

我如何创建一个 UIView,它像这张图片一样粘在 navigationBar 上。在这张图片上,即使你滚动它仍然会在那里:

enter image description here

最佳答案

你可以试试这个 enter image description here

 [self.navigationItem setTitle:@"Vijay"];

    UIImage *image = [UIImage imageNamed:@"tabarrrr"];
    [self.navigationController.navigationBar setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:image];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    [self.navigationController setNavigationBarHidden:FALSE];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];


//    
//    UIBarButtonItem *RigthButtonClicek=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"search.png"] style:UIBarButtonItemStylePlain target:self action:@selector(RigthButtonClicek:)];

    UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
    [button1 setFrame:CGRectMake(10.0, 2.0, 40, 20.0)];
    [button1 addTarget:self action:@selector(RigthButtonClicek:) forControlEvents:UIControlEventTouchUpInside];
    [button1 setImage:[UIImage imageNamed:@"cancelbtn.png"] forState:UIControlStateNormal];
    UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
    self.navigationItem.leftBarButtonItem = button;


    UIButton *button2=[UIButton buttonWithType:UIButtonTypeCustom];
    [button2 setFrame:CGRectMake(10.0, 2.0, 40, 20.0)];
    [button2 addTarget:self action:@selector(RigthButtonClicek:) forControlEvents:UIControlEventTouchUpInside];
    [button2 setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
    UIBarButtonItem *button3 = [[UIBarButtonItem alloc]initWithCustomView:button2];
    self.navigationItem.rightBarButtonItem = button3;

enter image description here

关于ios - 为导航栏创建一个粘性 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26177142/

相关文章:

ios - 我如何将其转换为 Swift?

ios - 正在提交 Flash Builder 4.6 应用程序到 Appstore : unsupported architecture(s): arm

python - 从 iOS 切换 python bool 值

iphone - Objective-C 类方法可用于子类吗?

iphone - 使用 UIWebview 中的当前 url 更新地址栏

iphone - 当网络激活(并准备播放)时,如何从 AVQueuePlayer/AVPlayerItem 获得回调?

ios - 是否可以在 iOS 模拟器上使用 2 个不同的设备?

objective-c - 如何获取有关媒体文件的特定信息(持续时间、比特率、FPS 等)

ios - 当执行[tableview reloadData]时,交互不起作用

iphone - 除了 MainWindow.xib 之外,是否可以创建没有单独 xib 的通用应用程序?