0

我真的很想像 instagram 的按钮一样做一个按钮(rightBarButtonItem),我认为不可能同时为按钮设置背景图像和图像。

看到这个

**

AppDelegate.m

**

NSDictionary *faTextAttributes = @{ UITextAttributeFont : [UIFont fontWithName:@"Arial" size: 12],
                                        UITextAttributeTextColor : [UIColor whiteColor],
                                        UITextAttributeTextShadowColor: [UIColor blackColor],
                                        UITextAttributeTextShadowOffset: [NSValue valueWithCGSize: CGSizeMake(0,0)] };


    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
     setTitleTextAttributes:faTextAttributes forState:UIControlStateNormal];
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
     setTitleTextAttributes:faTextAttributes forState:UIControlStateHighlighted];


    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
     setBackgroundImage:[UIImage imageNamed:@"bar"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
     setBackgroundImage:[UIImage imageNamed:@"bar"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

第一视图控制器.m

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];

self.navigationItem.rightBarButtonItem = rightButton;

这里的图像:

背景图片 (2x) http://d.pr/i/BYS9

刷新图像 (2x) http://d.pr/i/Hg5u


我在寻找什么来做 instagram 应用程序的相同按钮,在背景图像中设置刷新图像。

希望你能帮我解决这个问题。

4

1 回答 1

2

不幸的是 UIBarButtonItem 不是 UIButton 的子类,因此不具有 UIButton 所具有的复杂属性和可定制性。Instagram 完成此按钮的方式是仅将一张图像作为刷新图像叠加在背景图像上。当按下按钮时,他们隐藏项目并用风车替换它。

或者,您可以创建一个自定义按钮,将所需的属性添加到该按钮,然后使用该按钮创建栏项目:

UIBarButton* button initWithCustomView:customButton;

于 2013-04-08T14:54:20.027 回答