【发布时间】:2013-07-12 19:38:52
【问题描述】:
我正在尝试使用以下内容将 UIButton 添加到 UINavigationBar:
UIButton * addSource = [UIButton buttonWithType:UIButtonTypeCustom];
[addSource setBackgroundImage:[UIImage imageNamed:@"addsource.png"] forState:UIControlStateNormal];
[addSource addTarget: self action:@selector(addSourceButton:) forControlEvents:UIControlEventTouchUpInside];
[addSource setFrame: CGRectMake(115, 5, 32, 32)];
[navBar addSubview:addSource];
[addSource release];
但这不起作用,有什么想法吗?当我注释掉 setBackgroundImage 并将其更改为 setBackgroundColor 时,我可以看到它,但我似乎无法单击它(即:未触发它设置为的操作)。任何想法?将其更改为 UIImageView 而不是 UIButton 也可以,我可以很好地看到图像,所以这说明图像在那里。
【问题讨论】:
-
这段代码在哪里?
viewDidLoad? -
另外,你能显示
navBar的代码吗?
标签: iphone objective-c ios uinavigationbar