[self.tabBar setSelectionIndicatorImage:透明图片];
setSelectionIndicatorImage函数是设置tabbarItem选中时的背景图片
没有透明背景图片的话可以自己生成一张透明的图片。下面的函数就是根据UIColor生成UIImage的方法
- (UIImage *) createImageWithColor: (UIColor *) color
{
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
所以上面的问题可以写成:
[self.tabBar setSelectionIndicatorImage:[self createImageWithColor:[UIColor clearColor]]];
本文介绍如何使用Objective-C编程语言,通过自定义函数生成一张具有透明背景的图片,适用于设置UI界面中的tabbarItem选中状态背景。具体实现包括创建一个方法,接收颜色参数并返回一个带有该颜色且背景透明的UIImage实例。
2683

被折叠的 条评论
为什么被折叠?



