【发布时间】:2019-08-29 21:10:42
【问题描述】:
【问题讨论】:
-
您可以将带有此类图像的 uicustom 按钮用于 UIBarButtonItem。如果数字是可变的,那么您可以在按钮上添加一个 UILabel。希望对您有所帮助。
标签: ios
【问题讨论】:
标签: ios
使用它作为一种实用方法来为您的任何视图添加左栏按钮。进行明显的更改以获得右栏按钮。
+(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];
}
希望对你有所帮助。
【讨论】:
UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
【讨论】:
创建一个自定义按钮并使用它,即; [self.navController.leftBarButtonItem = customButton];
【讨论】: