突出显示的图像我想在UIButton
改变UIImage
,突显了。 UIButton
位于UINavigationController
。变化的UIButton在UINavigationBar的
我有以下代码:
UIView *containingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28, 28)];
UIButton *barUIButton = [UIButton buttonWithType:UIButtonTypeCustom];
[barUIButton setImage:[UIImage imageNamed:@"Add.png"] forState:UIControlStateNormal];
barUIButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
barUIButton.frame = CGRectMake(-9, 0, 28, 28);
[barUIButton addTarget:self action:@selector(addButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[barUIButton setImage:[UIImage imageNamed:@"AddHighlighted.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
[containingView addSubview:barUIButton];
UIBarButtonItem *containingBarButton = [[[UIBarButtonItem alloc] initWithCustomView:containingView] autorelease];
self.navigationItem.rightBarButtonItem = containingBarButton;
取而代之的是新的图像表现突出的时候,还有就是现有图像周围的黑色阴影。
这是为什么?
使用'png'文件和'imageNamed:'时,您不必指定文件扩展名。 '[UIImage imageNamed:@“Add”]'就足够了。 – 2012-03-06 00:14:00