How to stretch iOS UITabBarItem background in iOS

妖精的绣舞 提交于 2019-12-13 21:06:25

问题


This is what I'm using now:

tabBarController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"image.png"];

I have a couple pixels a of a solid color and I would like to stretch it the full width and height of my tabBarItem

How would you do this?


回答1:


This should help solve your problem

tabBarController.tabBar.selectionIndicatorImage = [[UIImage imageNamed:@"image.png"]
                  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

From Apple documentation

    During scaling or resizing of the image, areas covered by a cap are not scaled or 
resized. Instead, the pixel area not covered by the cap in each direction is tiled, left-to-
right and top-to-bottom, to resize the image. This technique is often used to create 
variable-width buttons, which retain the same rounded corners but whose center region grows
 or shrinks as needed. For best performance, use a tiled area that is a 1x1 pixel area in size.

Since we are setting the edge insets to be zero the image will be stetched to cover the entire area.



来源:https://stackoverflow.com/questions/19849627/how-to-stretch-ios-uitabbaritem-background-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!