Nun, hier ist was ich gefunden habe, ist, dass die Polsterung nur angezeigt, wenn die Größe veränderbar Bilder verwenden. Wenn Sie nicht veränderbare Bilder verwenden, ist das Padding nicht vorhanden.
Daher ist eine mögliche Lösung, UITabBar abzuleiten und die selectionIndicatorImage
immer zu konfigurieren, wenn sich die Artikelgröße ändert.
@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
Großartig! 2px auf jeder Seite reichen für iOS 7, ansonsten sehen die Item-Icons zum Rand hin verschoben aus. – hybridcattt