iPhone UIBarButtonItem 按钮图像的 alpha
我在下部工具栏添加了一个按钮,如下所示:
UIImage *locationImage = [UIImage imageNamed:@"193-location-arrow.png"];
UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithImage:locationImage style:UIBarButtonItemStyleBordered target:self action:@selector(updateCurrentLocation)];
NSArray *items = [[NSArray alloc] initWithObjects:locationButton,nil];
[toolbar setItems:items];
[items release];
[locationButton release];
这效果很好,图像的 alpha 拾取得很好,按钮显示如下:
因此,我对这段代码进行了稍微修改,在我的导航栏中创建了一个按钮:
UIImage *favouriteImage = [UIImage imageNamed:@"28-star.png"];
UIBarButtonItem *favouriteButton = [[UIBarButtonItem alloc] initWithImage:favouriteImage style:UIBarButtonItemStyleBordered target:self action:nil];
self.navigationItem.rightBarButtonItem = favouriteButton;
[favouriteButton release];
alpha 似乎没有在这个按钮上被拾取 - 它看起来是灰色的:
在导航栏中使用自定义图像时是否需要设置某些内容?
谢谢和问候,
丰富
I've added a button to a lower toolbar like this:
UIImage *locationImage = [UIImage imageNamed:@"193-location-arrow.png"];
UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithImage:locationImage style:UIBarButtonItemStyleBordered target:self action:@selector(updateCurrentLocation)];
NSArray *items = [[NSArray alloc] initWithObjects:locationButton,nil];
[toolbar setItems:items];
[items release];
[locationButton release];
This works great, the alpha of the image is picked up fine, the button displays like this:
So, I took this code and modified slightly to create a button in my navigation bar:
UIImage *favouriteImage = [UIImage imageNamed:@"28-star.png"];
UIBarButtonItem *favouriteButton = [[UIBarButtonItem alloc] initWithImage:favouriteImage style:UIBarButtonItemStyleBordered target:self action:nil];
self.navigationItem.rightBarButtonItem = favouriteButton;
[favouriteButton release];
The alpha doesn't seem to be picked up on this one - it looks greyed out:
Is there something I need to set when using custom images in the navigation bar?
Thanks and Regards,
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用几行代码将图像转换为白色:
You could convert the image to white with a few lines of code: