UIbarbuttonItem 在storyboard中如何关联action等
来源:互联网 发布:ubuntu设置语言为中文 编辑:程序博客网 时间:2024/05/17 03:49
1. 测试结果就是诡异啊:
UIBarButtonItem assigned action in Storyboard but not executing
http://stackoverflow.com/questions/9435105/uibarbuttonitem-assigned-action-in-storyboard-but-not-executing//
http://pastebin.com/45BiK1GR 这个家伙也说关联不work。。。
UIBarButtonItem does not divide actions in touch up inside and so on. It only has a click or selector, something like that
结论就是你最多就是可以知道按下没?如何关联selector? 不分touchup inside/outside了。
2. 在一组uibarbuttonitme中,有一个好像什么多没有设置,就可以关联到一个action,我靠。。。肯定是在storyboard设么地方搞了下。虽然我们选者了custome的controller class,估计还是通过storyboard和custom class组合成了一个controller。《这也能解释为啥自己使用的navigationcontroller是不能产生某类relation segue的》
后来就设置了sent actions关联到一个action 函数
那么我们来看建议:
1.通过segue
If the button will always take you to the next view (that is, there is no validation that needs to be performed on the current view before you can leave) then you can call your function from
prepareForSegue:
. Use segue.identifier
to work out which segue you are dealing with.2. 尝试通过IB中的send actions来设置
3. 代码来控制了;barItemUndo.action=@selector(undo);
============整理关于使用UInavigationcontroller ========
// Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; [self.window addSubview:navController.view]; //把自己的view设置上了
为什么类似以上的代码产生的
UINavigationController能够在一些场景下很好使用?某些情况无法使用?最好使用的就是有self。window的方式,以及addviewcontrollers方法中做参数 。如果只是一个nib,然后给他一个uinavigationcontroller,就有点麻烦。。。 以上的方面也就是把自己包了下,然后让windows加载了所谓的《rootviewcontroller》 这个要在IB中设置好像还不行呢!!!!!
initWithRootViewController
self.navigationItem.title = @"标题";
运行:
界面美工真是 ----无穷经,而来如此弄潮儿在viewDidLoad方法中,去掉self.navigationItem.title = @"标题";,并添加代码:
//自定义标题titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , 100, 44)];titleLabel.backgroundColor = [UIColor clearColor]; //设置Label背景透明titleLabel.font = [UIFont boldSystemFontOfSize:20]; //设置文本字体与大小titleLabel.textColor = [UIColor colorWithRed:(0.0/255.0) green:(255.0 / 255.0) blue:(0.0 / 255.0) alpha:1]; //设置文本颜色titleLabel.textAlignment = UITextAlignmentCenter;titleLabel.text = @"自定义标题"; //设置标题self.navigationItem.titleView = self.titleLabel;
运行:
self.navigationItem// //// title:::: titleView:::: (万能uiview接收器???)//左右按钮代码 //setbackgroundImagesetBackgroundImage
leftBarButtonItem设置的代码:
self.navigationItem.leftBarButtonItem = (UIBarButtonItem *)self.navigationItem.leftBarButtonItems = (UIBarButtonItem *)self.navigationItemsetLeftBarButtonItem:(UIBarButtonItem *)self.navigationItemsetLeftBarButtonItem:(UIBarButtonItem *) animated:(BOOL)self.navigationItemsetLeftBarButtonItems:(NSArray *)self.navigationItemsetLeftBarButtonItems:(NSArray *) animated:(BOOL)
//添加左按钮UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"左按钮" style:UIBarButtonItemStylePlain target:self action:@selector(myAction)];[self.navigationItem setLeftBarButtonItem:leftButton];
[UIBarButtonItemalloc]initWithBarButtonSystemItem:(UIBarButtonSystemItem) target:(id) action:(SEL)
用了系统自带的按钮样式,这些样式的标签和效果如下:《我觉得这个图不错,直观!》 其中有个 systemItemPageCurl只能在tool bar上显示的
标签 效果 标签 效果UIBarButtonSystemItemAction UIBarButtonSystemItemPause UIBarButtonSystemItemAdd UIBarButtonSystemItemPlay UIBarButtonSystemItemBookmarks UIBarButtonSystemItemRedo UIBarButtonSystemItemCamera UIBarButtonSystemItemRefresh UIBarButtonSystemItemCancel UIBarButtonSystemItemReply UIBarButtonSystemItemCompose UIBarButtonSystemItemRewind UIBarButtonSystemItemDone UIBarButtonSystemItemSave UIBarButtonSystemItemEdit UIBarButtonSystemItemSearch UIBarButtonSystemItemFastForward UIBarButtonSystemItemStop UIBarButtonSystemItemOrganize UIBarButtonSystemItemTrash UIBarButtonSystemItemPageCurl UIBarButtonSystemItemUndo
设置Navigation Bar背景图片
首先将准备好作为背景的图片拖到工程中,我用的图片名称是title_bg.png。
将上面的代码改成:
//设置Navigation Bar背景图片UIImage *title_bg = [UIImage imageNamed:@"title_bg.png"]; //获取图片CGSize titleSize = self.navigationController.navigationBar.bounds.size; //获取Navigation Bar的位置和大小title_bg = [self scaleToSize:title_bg size:titleSize];//设置图片的大小与Navigation Bar相同[self.navigationController.navigationBar setBackgroundImage:title_bg forBarMetrics:UIBarMetricsDefault]; //设置背景
- UIbarbuttonItem 在storyboard中如何关联action等
- 如何在xcode中使用storyboard
- 如何在storyboard中使用navigationcontrol
- 如何在xcode中使用storyboard
- 如何在xcode中使用storyboard
- 如何在xcode中使用storyboard
- 如何在XCode7中不使用Storyboard
- 关于mysql中如何显示中文及在myeclipse上关联mysql等的一些小结
- IOS如何在StoryBoard中添加竖向滑动的ScrollView
- 如何在storyBoard中实现UIimageView长宽相等
- 如何在xib/storyboard中设置视图的属性,如圆角?
- 如何在Swift中创建Action扩展
- 如何在action中访问servlet API
- 如何在Swift中创建Action扩展
- 如何在LR中做关联-Zee
- 如何在 LoadRunner 脚本中做关联
- 如何在myeclipse中关联android源码
- 如何在LoadRunner脚本中做关联
- 深圳好的IT公司
- Away3D Error: Error #3669: 输入大小错误。
- 文本分类_中英文分类的异同
- B树、B-树、B+树、B*树
- 关于程序的编译和链接
- UIbarbuttonItem 在storyboard中如何关联action等
- $(document).ready(function()
- Android JNI知识简介
- C++中常见类型取值范围
- c语言变量名规则
- 图像傅里叶变换
- 三十分钟掌握STL
- 同步/异步与阻塞/非阻塞的区别
- Struts1和Struts2的区别和对比