IOS实现自定义透明背景的tabbar
程序员文章站
2023-12-13 09:20:28
话不多说,直接看示例代码
```
// uiimageview *imageview = [[uiimageview alloc]initwithframe:...
话不多说,直接看示例代码
``` // uiimageview *imageview = [[uiimageview alloc]initwithframe:cgrectmake(0, 0, kscreenw, tabbarheight + 5)]; // [imageview setimage:[self createimagewithcolor:[uicolor clearcolor]]]; // [imageview setcontentmode:uiviewcontentmodescaletofill]; // [self.tabbar insertsubview:imageview atindex:0]; //覆盖原生tabbar的上横线 // [[uitabbar appearance] setshadowimage:[self createimagewithcolor:[uicolor clearcolor]]]; //背景图片为透明色 // [[uitabbar appearance] setbackgroundimage:[self createimagewithcolor:[uicolor clearcolor]]]; self.tabbar.backgroundcolor = [uicolor clearcolor]; //设置为半透明 self.tabbarcontroller.tabbar.translucent = yes; ``` ``` -(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; } ```
以上就是在ios实现自定义透明背景的tabbar的全部内容,希望这篇文章对大家能有所帮助。