【问题标题】:UIBarButtonItem with Image [closed]带有图像的 UIBarButtonItem [关闭]
【发布时间】:2019-08-29 21:10:42
【问题描述】:

我想创建一个看起来完全像这样的UIBarButtonItem

我怎样才能做到这一点?

【问题讨论】:

  • 您可以将带有此类图像的 uicustom 按钮用于 UIBarButtonItem。如果数字是可变的,那么您可以在按钮上添加一个 UILabel。希望对您有所帮助。

标签: ios


【解决方案1】:

使用它作为一种实用方法来为您的任何视图添加左栏按钮。进行明显的更改以获得右栏按钮。

+(void)setMenuButton:(UIViewController *)viewController
{
UIImage *listIcon= [UIImage imageNamed:@"YourImageName"];
UIButton *rightBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[rightBarButton setBackgroundImage: listIcon forState:UIControlStateNormal];
[rightBarButton addTarget: viewController.navigationController.parentViewController action:@selector(barButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
rightBarButton.frame = CGRectMake(0, 0, 40, 30);
rightBarButton.tag = BAR_BUTTON_TAG;
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightBarButton];
}

希望对你有所帮助。

【讨论】:

    【解决方案2】:
    UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"]
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
    [[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
        barMetrics:UIBarMetricsDefault];
    

    【讨论】:

      【解决方案3】:

      创建一个自定义按钮并使用它,即; [self.navController.leftBarButtonItem = customButton];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多