gpt4 book ai didi

ios - 导航 Controller 中的图像设置不正确

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:55 25 4
gpt4 key购买 nike

我写了下面的代码...

enter image description here

      if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {

//iOS 5
UIImage *toolBarIMG = [UIImage imageNamed: @"header.png"];

if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[self.navigationController.navigationBar setBackgroundImage:toolBarIMG
forBarMetrics:0];
} else {

//iOS 4
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header.png"]]
atIndex:0];

}

图像显示在导航 Controller 中,但在图像的开始和结束处存在一些像素间隙,显示为黑色图像。如何设置图像以便去除黑色。你可以看到粉红色的圆形,我想去掉那些黑色..

提前致谢。

最佳答案

这是将图像设置到导航栏的方式

UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"header.png"];
[navBar setBackgroundImage:image];

并将这段代码放在下面的方法中

- (void)viewWillAppear:(BOOL)animated

将您的 BarMetrics 设置为默认值

 if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {

//iOS 5
UIImage *toolBarIMG = [UIImage imageNamed: @"header.png"];

if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[self.navigationController.navigationBar setBackgroundImage:toolBarIMG
forBarMetrics:UIBarMetricsDefault];
} else {

//iOS 4
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header.png"]]
atIndex:0];

关于ios - 导航 Controller 中的图像设置不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13643354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com