好吧,我发现只有在使用可调整大小的图像时才会出现填充。使用不可调整大小的图像时,填充不存在。
因此,一个可能的解决方案是子类化 UITabBar 并selectionIndicatorImage在项目大小更改时配置。
@interface TKTabBar
@end
@implementation TKTabBar
{
    CGSize _selectionIndicatorImageSize;
}
- (void)tk_refreshSelectionIndicatorImageForItemSize:(CGSize)itemSize
{
    // Recompute the selection indicator image only if the size of the item has changed.
    if (!CGSizeEqualToSize(itemSize, _selectionIndicatorImageSize))
    {
        _selectionIndicatorImageSize = itemSize;
        // Compute here the new image from the item size.
        // In this example I'm using a Cocoa Pod called UIImage+Additions to generate images dynamically.
        UIImage *redImage = [UIImage add_imageWithColor:[UIColor add_colorWithRed255:208 green255:75 blue255:43] size:CGSizeMake(itemSize.width, 2)];
        UIImage *clearImage = [UIImage add_imageWithColor:[UIColor clearColor] size:CGSizeMake(itemSize.width, itemSize.height)];
        UIImage *mixImage = [clearImage add_imageAddingImage:redImage offset:CGPointMake(0, itemSize.height-2)];
        // Finally, I'm setting the image as the selection indicator image.
        [self setSelectionIndicatorImage:mixImage];
    }
}
// Using the layout subviews method to detect changes on the tab size
- (void)layoutSubviews
{
    [super layoutSubviews];
    // Only needed if at least one item
    if (self.items.count > 0)
    {
        CGSize itemSize = CGSizeZero;
        // Iterating over all subviews
        for (UIView *view1 in self.subviews)
        {
            // Searching for "UITabBarButtons"
            if ([view1 isKindOfClass:NSClassFromString(@"UITabBarButton")])
            {
                itemSize = view1.bounds.size;
                break;
            }
        }
        // Applying the new item size
        [self tk_refreshSelectionIndicatorImageForItemSize:itemSize];
    }
}
@end