8
A
回答
9
转到iPhone Interface Guidelines Page。
在“用于表格行和其他用户界面元素的标准按钮”下复制ContactAdd按钮(我将它另存为ContactAdd.png)。将其添加到您的项目中。
在的cellForRowAtIndexPath:(NSIndexPath *)indexPath方法Add:
UIImage *image = [UIImage imageNamed:@"ContactAdd.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; //You can also Use: //UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height); //match the button's size with the image size button.frame = frame; [button setBackgroundImage:image forState:UIControlStateNormal]; // set the button's target to this table view controller so you can open the next view [button addTarget:self action:@selector(yourFunctionToNextView:) forControlEvents:UIControlEventTouchUpInside]; button.backgroundColor = [UIColor clearColor]; cell.accessoryView = button;
27
如果你有一个导航栏,你应该添加的UIBarButtonItem这样的:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(addButtonPressed:)];
self.navigationItem.rightBarButtonItem = addButton;
+0
谢谢。帮助过我。 Upvote给你。 – DrinkJavaCodeJava 2014-03-23 18:15:40
2
对于斯威夫特
let addButton = UIBarButtonItem.init(barButtonSystemItem: .Add,
target: self,
action: #selector(yourFunction))
self.navigationItem.rightBarButtonItem = addButton
相关问题
- 1. 将按钮添加到标题右侧
- 2. 如何将一个按钮添加到UITableView条目的右侧?
- 3. iOS添加按钮到UITableViewHeaderFooterView右侧
- 4. 将按钮列添加到C#或VB.NET中的DataGridView的右侧
- 5. 在Odoo窗体视图的右侧栏添加按钮
- 6. 如何将按钮添加到表格视图中的单元格
- 7. 如何将滚动箭头按钮添加到左侧和右侧滚轮
- 8. 将图像添加到右侧将下方的表格向右推
- 9. 将标签添加到切换按钮的右侧
- 10. 如何将“全屏”按钮添加到最右侧的标题栏中?
- 11. 无法将按钮添加到表格视图工具栏
- 12. 将多个水平按钮添加到表格视图
- 13. 将侧按钮图像添加到按钮
- 14. 将图像添加到列表视图中的按钮
- 15. 如何将后退图标添加到左侧栏按钮?
- 16. 将按钮添加到树视图行
- 17. 我如何在表格的左侧和右侧添加阴影
- 18. 如何将项目添加到按钮单击列表视图?
- 19. 如何将按钮添加到列表视图?
- 20. 将按钮添加到左侧UINavigatorcontroller iOS4
- 21. 如何将按钮对齐到右侧?
- 22. Android添加按钮到列表视图
- 23. 如何在JavaFX表格视图中添加按钮
- 24. 如何将按钮方面的框架添加到视图中?
- 25. 将按钮添加到表格脚注
- 26. 添加自定义按钮,在列表视图右侧在android系统
- 27. 将左右边距添加到UITableViewController里面的表格视图
- 28. 如何将图像添加到按钮?
- 29. 如何将图片按钮添加到表格中而无需缓慢加载
- 30. 如何将图标添加到NSMenuItem的右侧
* NOTE: 除了复制和添加,您还可以使用:[UIButton buttonWithType:UIButtonTypeContactAdd];而不是UIButtonTypeCustom。 – erastusnjuki 2010-02-16 13:36:19
执行这些任务之一的棘手部分是将参数传递给yourFunctionToNextView:以便知道哪一行被按下。 这可以通过button.tag = row轻松完成; 但是,如果你的表中有一些部分,那么一个int就不够好。你需要传递indexPath。我在这里发现了这种方法来做这样的事情。 http://stackoverflow.com/questions/5500327/subclass-uibutton-to-add-a-property – roocell 2011-12-25 14:45:20
传递参数是棘手的部分。您的链接几乎完成,除非它不告诉您如何传递添加到UIButton类的属性。为了完成这个想法,仅当在选择器中的“yourFunctionToNextView:”之后包含“:”时才会传递该参数。所以上面的例子可以通过button.property = indexPath来扩展。然后,选择器的定义是: - (void)yourFunctionToNextView:(UIButton *)sender {}。然后在这个方法中,你可以使用类似NSIndexPath * indexPath = sender.property;其中属性是indexPath。 – JeffB6688 2013-04-10 21:46:53