Woo*_*tty 11 iphone xcode uinavigationcontroller uibarbuttonitem
我在导航栏上有一个UIBarButtonItem.我想把它做成箭头形状.我的意思是我希望它是正方形,除了尖尖的一面.有谁知道如何做到这一点?
谢谢!
小智 17
我在这个问题上采用了几种方法,并最终使用多个来源的所有答案进行了解决.有几个技巧; 这个片段会显示所有内容(我正在创建一个自定义rightNavButton
,但你可以轻松地适应任何UIBarButtonItem
):
// Produces a nice "right arrow" style button that mirrors the back arrow
// automatically added by the navController
//
UIImage *buttonImage = [UIImage imageNamed:@"forwardButton.png"];
UIButton *forwardButton = [UIButton buttonWithType:UIButtonTypeCustom];
[forwardButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[forwardButton setTitle:@"Meter" forState:UIControlStateNormal];
forwardButton.font = [UIFont boldSystemFontOfSize:12];
forwardButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[forwardButton addTarget:self action:@selector(showMeter)
forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:forwardButton];
Run Code Online (Sandbox Code Playgroud)
注意:事实证明,如果您尝试在使用UIButton
不需要的自定义视图分配自定义视图后直接在按钮项上设置目标和操作- 您必须在按钮本身上设置目标和操作 - 显然是navBar
用途按钮提供逐字.
这是我在不透明黑色上使用的图像navBar
(显然你可以使用任何东西):http://raretiger.com/images/forwardbutton.png
制作自定义背景.有关方法,请参阅在UIToolbar上创建左箭头按钮(如UINavigationBar的"后退"样式).
你可以-pushNavigationItem:animated:
使内置的后退按钮出现,但你不能指定自定义操作它.
对于未记录的方法,您可以使用
UIButton* backButton = [UIButton buttonWithType:101];
Run Code Online (Sandbox Code Playgroud)
创建一个后退"按钮".
归档时间: |
|
查看次数: |
33475 次 |
最近记录: |