我用barbutton创建了视图,如下所示
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"settingsicon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonClicked:)];
这是这样的 但我希望它为
如何删除按钮的边框?
答案 0 :(得分:16)
使用此:
UIBarButtonItem *barButton= [[UIBarButtonItem alloc] initWithCustomView:customButton];
您可以使用您想要的任何视图初始化按钮。您可以在其中创建一个包含任何(可接受的)视图的按钮。
例如
// GRAPHICAL BUTTON FRAMEWORK
UIButton* btton = [UIButton buttonWithType:UIButtonTypeCustom];
[btton setFrame:CGRectMake(0, 0, 30, 30)];
[btton addTarget:self action:@selector(SOMEROUTINE) forControlEvents:UIControlEventTouchUpInside];
[btton setImage:[UIImage imageNamed:@"SOME IMAGE"] forState:UIControlStateNormal];
UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithCustomView:btton];
希望它对你有所帮助。
答案 1 :(得分:15)
另一种方法是删除按钮的背景图像:
// portrait
[self.navigationItem.leftBarButtonItem setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
// landscape
[self.navigationItem.leftBarButtonItem setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];