简体   繁体   English

Instagram般的刷新按钮

[英]Instagram-like refresh button

I'm really tried to do a button (rightBarButtonItem) like the instagram's button, I think is not possible to set background-image & image to the button in the same time. 我真的试图像Instagram的按钮那样做一个按钮(rightBarButtonItem),我认为不可能同时在按钮上设置背景图像和图像。

See this in 看到这个

** **

AppDelegate.m 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];

FirstViewController.m FirstViewController.m

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

self.navigationItem.rightBarButtonItem = rightButton;

Here the images: 这里的图像:

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

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


What im looking for to do the same button of instagram application, set the refresh image inside the background image. 我正在寻找做instagram应用程序的相同按钮,在背景图像中设置刷新图像。

Hope you help me about this. 希望你帮我这个。

Unfortunately UIBarButtonItem is not a subclass of UIButton and therefore does not have the complex properties and customizability that UIButton has. 不幸的是,UIBarButtonItem不是UIButton的子类,因此不具备UIButton具有的复杂属性和可定制性。 The way Instagram is accomplishing this button is to have only one image that is the Refresh image superimposed over the background image. Instagram实现此按钮的方式是只有一个图像是覆盖在背景图像上的刷新图像。 When the button is pressed, they hide the item and replace it with pinwheel. 按下按钮时,它们会隐藏物品并用风车将其更换。

alternatively you could create a custom button, add your desired attributes to that button and then use that button to create the bar items: 或者,您可以创建自定义按钮,将所需属性添加到该按钮,然后使用该按钮创建条形项:

UIBarButton* button initWithCustomView:customButton;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM