标签:
UIMenuController的方法:
1.创建menucontroller
+ (UIMenuController *)sharedMenuController;
2.设置是否可见
- (void)setMenuVisible:(BOOL)menuVisible animated:(BOOL)animated;
3.设置显示的位置
- (void)setTargetRect:(CGRect)targetRect inView:(UIView *)targetView;
4.有一个存储数据的属性:@property(nullable, nonatomic,copy) NSArray<UIMenuItem *> *menuItems;
用set方法来调用,例如:
[menu setMenuItems:[NSArray arrayWithObjects:copyItem,resendItem,resendItem1,resendItem2,resendItem3,nil]];
UIMenuItem的使用:
- (instancetype)initWithTitle:(NSString *)title action:(SEL)action;
例子:
//设置menucontroller的数据源
- (NSArray *)showMenuItems
{
NSMutableArray *array = [NSMutableArray array];
UIMenuItem *deleteItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteItem:)];
[array addObject:deleteItem];
if (_msg.status == EIMAMsg_SendFail)
{
UIMenuItem *resendItem = [[UIMenuItem alloc] initWithTitle:@"重发" action:@selector(resendItem:)];
[array addObject:resendItem];
}
return array;
}
//设置menucoller的属性
- (void)showMenu
{
NSArray *showMenus = [self showMenuItems];
if (showMenus.count)
{
[self becomeFirstResponder];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:showMenus];
[menu update];
[menu setTargetRect:_contentBack.frame inView:self.contentView];
[menu setMenuVisible:YES animated:YES];
}
}
UIMenuController和UIMenuItem的使用
标签:
原文地址:http://www.cnblogs.com/lyz0925/p/5648355.html