我在Objective-C中发展。我想更改标签栏背景,如下图所示:
代码如下:
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbaritem_background.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
但是在设置背景图片后,背景不在正确的位置,如下所示:
背景图片应放在底部,就像上图中的背景一样。
我错过了什么吗?有人能帮助我吗?
提前致谢。
答案 0 :(得分:2)
我认为在某个地方你出错了,请检查这是否是这个步骤:
在/* this is to test whether the program ignores imbalances in the comment blocks */
public class Test3 {
public static void main(String[] args) {
boolean haveYouWatchedHamiltonYet = true;
int theSchuylerSisters = 3;
int alexanderhamilton = 1;
int aaronburr = 1;
boolean amIintheroom = theRoomWhereItHappens();
/* this is a commented block. We're testing if your code
can deal with unbalanced things in the comments: /*
that was the test for here */
}
/*just a general comment */
/* this one has some errors /* { [ { [ } ] */
public boolean theRoomWhereItHappens() {
boolean intheRoomWhereItHappens = false;
boolean isHappyAboutThis = false;
return intheRoomWhereItHappens && isHappyAboutThis;
}
}
中,您可以设置标签栏免费颜色:
ViewController.m
结果如下:
答案 1 :(得分:0)
我认为您可以尝试使用方法- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
,因为您的背景图像的大小不等于tabbar&size;
答案 2 :(得分:0)
尝试使用此方法将图像更改为ScaleImage。
+(UIImage *)getScaleImageNamed:(NSString *)name{
UIImage *nomalImage = [UIImage imageNamed:name];
CGFloat hInset = floorf(nomalImage.size.width / 2);
CGFloat vInset = floorf(nomalImage.size.height / 2);
UIImage *res = [nomalImage resizableImageWithCapInsets:UIEdgeInsetsMake(vInset, hInset, vInset, hInset)];
return res;
}
答案 3 :(得分:0)
您可能会错过的步骤,希望可以提供帮助。
Assets.xcassets
)resizableImageWithCapInsets:
调整背景图片大小将UIAppearance
设置放在AppDelegate.m
:
[[UITabBar appearance] setBackgroundImage:[[UIImage imageNamed:@"tabbaritem_background.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]];