Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabbar的黑线,能否自定义颜色? #388

Closed
freesan44 opened this issue Jun 17, 2019 · 10 comments
Closed

Tabbar的黑线,能否自定义颜色? #388

freesan44 opened this issue Jun 17, 2019 · 10 comments

Comments

@freesan44
Copy link

enter image description here



Base Info for this issue

  1. Version:Latest Version as here
  2. Language of App :Objective-C
  3. iOS System Version:iOS12
  4. Prototype(是否是真机):YES
  5. Issue Type:Crash、Bug、Enhancement(希望能支持一个新需求)、Q-A

1. How to reproduce the problem.

//以下方法能把顶部黑线隐藏掉,但目前的需求是改变黑线的颜色,请问能否实现
[mainCon hideTabBadgeBackgroundSeparator];
我通过以上方式看到获取的是一个UIImageView,所以我把ImageView的填充颜色改为红色,但还是没法生效,具体代码如下:
[mainCon.tabBar layoutIfNeeded];
UIImageView * tabBadgeBackgroundSeparatorImgView = mainCon.tabBar.cyl_tabBadgeBackgroundSeparator;
[tabBadgeBackgroundSeparatorImgView setImage:[tabBadgeBackgroundSeparatorImgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
tabBadgeBackgroundSeparatorImgView.tintColor = kRedColor;

2. Please help me in this way.

3. Here is a Demo.

4. Here is my Debug log


@ChenYilong
Copy link
Owner

tabbar 的 background image 有值时,shadow image设置才会生效。

@ChenYilong
Copy link
Owner

demo演示代码里注释里说明了。

@freesan44
Copy link
Author

demo演示代码里注释里说明了。

您好,谢谢回复!
如果我修改[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
这里只是修改背景图,我想实现的需求是,【tabbar顶部的黑线/灰线修改成红色】

@ChenYilong
Copy link
Owner

自定义shadowImageview不生效吗?

@freesan44
Copy link
Author

自定义shadowImageview不生效吗?

可以了,谢谢!

@ChenYilong
Copy link
Owner

怎么生效的,上面的代码做了什么改动?
贴下用法吧。

@freesan44
Copy link
Author

怎么生效的,上面的代码做了什么改动?
贴下用法吧。

UIGraphicsBeginImageContextWithOptions(CGSizeMake(kCutUIWidth(375), 1), 0, [UIScreen mainScreen].scale);
[UIColorFromRGB(0xe6e6e6) set];
UIRectFill(CGRectMake(0, 0,kCutUIWidth(375), 1));
UIImage *ColorImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UITabBar appearance] setShadowImage:ColorImg];

自定义一张1像素高度的纯颜色的image,然后放在setShadowImage里面

@ChenYilong
Copy link
Owner

ChenYilong commented Jun 18, 2019

你上面的代码有一个前提,必须调用了下面的代码:
因为背景是空的话,设置分割线也会生效。

     [[UITabBar appearance] setBackgroundImage:someImage];

@freesan44
Copy link
Author

是的

@ChenYilong
Copy link
Owner

//去除 TabBar 自带的顶部阴影
需要使用 -[CYLTabBarController hideTabBarShadowImageView] 

见README

并参考:#386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants