iOS中UIMenuController基本使用
2016-02-23 11:26
555 查看
我这里用了一个按钮,点击按钮的时候给弹出UIMenuController控件
下面的代码是按钮触发事件:
-(void)showPopupView:(UIButton *)button
{
button.selected = !button.selected;
//必须要有,如果要UIMenuController显示
[self
becomeFirstResponder];
_menuController = [UIMenuController
sharedMenuController];
UIMenuItem *menuitem_01 = [[UIMenuItem
alloc] initWithTitle:@"delete"
action:@selector(deleteAction)];
UIMenuItem *menuitem_02 = [[UIMenuItem
alloc] initWithTitle:@"copy"
action:@selector(copyAction)];
UIMenuItem *menuitem_03 = [[UIMenuItem
alloc] initWithTitle:@"cancel"
action:@selector(cancelAction)];
_menuController.menuItems = [NSArray
arrayWithObjects:menuitem_01, menuitem_02, menuitem_03,
nil];
[_menuController
setTargetRect:CGRectMake(button.frame.origin.x, button.frame.origin.y,
button.frame.size.width,
30) inView:self.view];
[_menuController
setMenuVisible:YES
animated:YES];
}
//必须要有,如果要UIMenuController显示
-(BOOL)canBecomeFirstResponder
{
return
true;
}
//监听自己的定义事件,是 return YES;
否 return NO
即移除系统;
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action ==
@selector(deleteAction) || action == @selector(copyAction) || action ==
@selector(cancelAction)) {
return YES;
}
return
NO;
}
我想改变下UIMenuController的背景色,默认是黑色的,但是不知道怎么改动,如果你有办法请给我留言,谢谢!
下面的代码是按钮触发事件:
-(void)showPopupView:(UIButton *)button
{
button.selected = !button.selected;
//必须要有,如果要UIMenuController显示
[self
becomeFirstResponder];
_menuController = [UIMenuController
sharedMenuController];
UIMenuItem *menuitem_01 = [[UIMenuItem
alloc] initWithTitle:@"delete"
action:@selector(deleteAction)];
UIMenuItem *menuitem_02 = [[UIMenuItem
alloc] initWithTitle:@"copy"
action:@selector(copyAction)];
UIMenuItem *menuitem_03 = [[UIMenuItem
alloc] initWithTitle:@"cancel"
action:@selector(cancelAction)];
_menuController.menuItems = [NSArray
arrayWithObjects:menuitem_01, menuitem_02, menuitem_03,
nil];
[_menuController
setTargetRect:CGRectMake(button.frame.origin.x, button.frame.origin.y,
button.frame.size.width,
30) inView:self.view];
[_menuController
setMenuVisible:YES
animated:YES];
}
//必须要有,如果要UIMenuController显示
-(BOOL)canBecomeFirstResponder
{
return
true;
}
//监听自己的定义事件,是 return YES;
否 return NO
即移除系统;
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action ==
@selector(deleteAction) || action == @selector(copyAction) || action ==
@selector(cancelAction)) {
return YES;
}
return
NO;
}
我想改变下UIMenuController的背景色,默认是黑色的,但是不知道怎么改动,如果你有办法请给我留言,谢谢!
相关文章推荐
- Android判断手机是否是小米MIUI系统
- hdu 1242 Rescue(A*索搜)
- UIImage实现gif文件播放
- UICollectionView基础
- iOS UITabBarController封装
- easyui后台取值一般是主键id进行删除
- 第一章 遇见HADOOP 第二节 数据存储与分析(hadoop:the definitive guide)
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- String,StringBuffer,StringBuilder的一些面试题
- arduino循迹小车
- uvaoj-540:team queue
- Android Studio配置svn时提示需要证书:authentication required的解决方法
- 我的红外arduino链接,!!!!
- RequireJS进阶(三)
- 关于在scrollview滚动时 键盘的弹出适配
- RequireJS进阶(二)
- RequireJS进阶(一)
- RequireJS入门(三)
- UITableViewCell等控件字体随系统字体变化的解决方案
- 默认通知QuickSettings的默认行数列数