FTPopOverMenu
FTPopOverMenu
是为 iOS
设计的弹出菜单,可能是最容易使用的一个,支持横竖屏两种模式。可以从任何 UIView
,任何 UIBarButtonItem
和任何 CGRect
显示。最简单的 API,允许您在一行代码中更改样式。
菜单数支持以下上下文
- 图片名称 (NSString, 仅主包),
- 图片 (UIImage),
- 图片远程 URL 字符串 (NSString),
- 图片远程 URL (NSURL),
- 模型 (FTPopOverMenuModel, 支持选中状态)
⚠️ 自 1.3.6
到 2.0.0
的大 API 变更 (更多信息请查看 版本变更日志)
- 支持分开配置。
- 将 'tintColor' 更改为 'backgroundColor'
关于 Swift 版本
FTPopOverMenu_Swift
现已发布。 现在查看 Swift 版本。这个 Swift 版本与这个 Objective-C 版本的 API 相同。
屏幕截图
最近UrbanHooker增加了圆形箭头支持,我进行了一点点修改。
安装
手动
- 克隆此仓库。
- 将 '/FTPopOverMenu' 文件夹简单拖入您的项目中。
- 导入 'FTPopOverMenu.h'
CocoaPods
FTPopOverMenu
通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'FTPopOverMenu'
使用方法
自定义
显示前对以下设置进行修改(仅修改您想更改的设置):
FTPopOverMenuConfiguration *configuration = [FTPopOverMenuConfiguration defaultConfiguration];
configuration.menuRowHeight = ...
configuration.menuWidth = ...
configuration.textColor = ...
configuration.textFont = ...
configuration.tintColor = ...
configuration.borderColor = ...
configuration.borderWidth = ...
configuration.textAlignment = ...
configuration.ignoreImageOriginalColor = ...;// set 'ignoreImageOriginalColor' to YES, images color will be same as textColor
configuration.allowRoundedArrow = ...// Default is 'NO', if sets to 'YES', the arrow will be drawn with round corner.
configuration.separatorColor = ...
configuration.shadowColor = ... // Default is black
configuration.shadowOpacity = ... // Default is 0 - choose anything between 0 to 1 to show actual shadow, e.g. 0.2
configuration.shadowRadius = ... // Default is 5
configuration.shadowOffsetX = ...
configuration.shadowOffsetY = ...
setTintColor,默认为灰色。在1.2.0版本后被弃用
[FTPopOverMenu setTintColor:[UIColor redColor]];
setTextColor,默认为白色。在1.2.0版本后被弃用
[FTPopOverMenu setTextColor:[UIColor blackColor]];
setPreferedWidth,默认为120,不应小于50。在1.2.0版本后被弃用
[FTPopOverMenu setPreferedWidth:200];
从发送视图, 无图像菜单。
[FTPopOverMenu showForSender:sender
withMenu:@[@"MenuOne",@"MenuTwo",@"MenuThr"]
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
从发送视图, 含图像菜单。
[FTPopOverMenu showForSender:sender
withMenu:@[@"MenuOne",@"MenuTwo",@"MenuThr"]
imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
从发送视图,含图像菜单,自定义配置。
[FTPopOverMenu showForSender:sender
withMenu:@[@"MenuOne",@"MenuTwo",@"MenuThr"]
imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
configuration:customConfiguration
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
来自发送方帧/导航项,无图片菜单。
[FTPopOverMenu showFromSenderFrame:CGRectMake(self.view.frame.size.width - 40, 20, 40, 40)
withMenu:@[@"123",@"234",@"345"]
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
来自发送方帧/导航项,含图片菜单。
[FTPopOverMenu showFromSenderFrame:CGRectMake(self.view.frame.size.width - 40, 20, 40, 40)
withMenu:@[@"123",@"234",@"345"]
imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
来自发送方帧/导航项,含图片菜单,自定义配置。
[FTPopOverMenu showFromSenderFrame:CGRectMake(self.view.frame.size.width - 40, 20, 40, 40)
withMenu:@[@"123",@"234",@"345"]
imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
configuration:customConfiguration
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
来自barButtonItems。
- 第一步:将操作与事件添加到您的barButtonItems中。
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleDone target:self action:@selector(onNavButtonTapped:event:)]];
- 第二步:实现操作,也支持自定义配置。
-(void)onNavButtonTapped:(UIBarButtonItem *)sender event:(UIEvent *)event
{
[FTPopOverMenu showFromEvent:event
withMenu:@[@"123",@"234",@"345"]
imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
configuration:customConfiguration
doneBlock:^(NSInteger selectedIndex) {
} dismissBlock:^{
}];
}
变更日志
更多
- 由@Tobaloidee设计logo
- 演示中的图片来自https://www.iconfinder.com/iconsets/pokemon-go。
- 如果您喜欢它,或者可能想在您的项目中使用它,请给我一个
star
。 - 想要另寻一种方法来做这件事?来看看我的FTPopMenu吧。这另一种显示弹出菜单的方式,由
UIPopoverViewController
包装而来,更具有遗传性和更美观。不妨试一试。
授权
FTPopOverMenu
可在MIT
授权下使用。更多详情请参阅LICENSE
文件。