Giter Site home page Giter Site logo

liufengting / ftpopovermenu Goto Github PK

View Code? Open in Web Editor NEW
1.0K 30.0 171.0 3.4 MB

FTPopOverMenu is a pop over menu for iOS which is maybe the easiest one to use. Supports both portrait and landscape. It can show from any UIView, any UIBarButtonItem and any CGRect.

License: MIT License

Objective-C 97.81% Ruby 2.19%
pop navigation-items menu button cocoapods popover

ftpopovermenu's Introduction

FTPopOverMenu

FTPopOverMenu

Twitter GitHub license Version Codebeat badge Download CocoaPods CocoaPods CI Status GitHub stars Gitter

FTPopOverMenu is a pop over menu for iOS which is maybe the easiest one to use, supports both portrait and landscape. It can show from any UIView, any UIBarButtonItem and any CGRect. Simplest APIs, enable you to change the style in one line of code.

menu array supports following context:

  • image name (NSString, only main bundle),
  • image (UIImage),
  • image remote URL string (NSString),
  • image remote URL (NSURL),
  • model (FTPopOverMenuModel, select state support)

⚠️ Big API Change from 1.3.6 to 2.0.0 (See CHANGELOG for more info)

  • supports separated configuration.
  • change 'tintColor' to 'backgroundColor'

About Swift Version

FTPopOverMenu_Swift is now published. Take a look at it now. The swift version has same APIs with this OC version.

ScreenShots

screenshots

Recently UrbanHooker added round arrow support, I changed a little bit.

screenshots

Installation

Manually

  • clone this repo.
  • Simply drop the '/FTPopOverMenu' folder into your project.
  • import 'FTPopOverMenu.h'

CocoaPods

FTPopOverMenu is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'FTPopOverMenu'

Usage

Customize

Do any of the following settings to set the style (Only set the ones you want to change) before showing.

    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, default is gray color. deprecated after 1.2.0

    [FTPopOverMenu setTintColor:[UIColor redColor]];

setTextColor, default is white color. deprecated after 1.2.0

    [FTPopOverMenu setTextColor:[UIColor blackColor]];

setPreferedWidth, default is 120, should not be less than 50. deprecated after 1.2.0

    [FTPopOverMenu setPreferedWidth:200];

From SenderView, Menu Without Images.

    [FTPopOverMenu showForSender:sender
                        withMenu:@[@"MenuOne",@"MenuTwo",@"MenuThr"]
                       doneBlock:^(NSInteger selectedIndex) {
                           
                       } dismissBlock:^{
                          
                       }];

From SenderView, Menu With Images.

    [FTPopOverMenu showForSender:sender
                        withMenu:@[@"MenuOne",@"MenuTwo",@"MenuThr"]
                  imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
                       doneBlock:^(NSInteger selectedIndex) {
                           
                       } dismissBlock:^{
                          
                       }];

From SenderView, Menu With Images, custom configuration.

    [FTPopOverMenu showForSender:sender
                        withMenu:@[@"MenuOne",@"MenuTwo",@"MenuThr"]
                  imageNameArray:@[@"setting_icon",@"setting_icon",@"setting_icon"]
                   configuration:customConfiguration
                       doneBlock:^(NSInteger selectedIndex) {
                           
                       } dismissBlock:^{
                          
                       }];

From SenderFrame/NavigationItem, Menu Without Images.

    [FTPopOverMenu showFromSenderFrame:CGRectMake(self.view.frame.size.width - 40, 20, 40, 40)
                              withMenu:@[@"123",@"234",@"345"]
                             doneBlock:^(NSInteger selectedIndex) {
                                 
                             } dismissBlock:^{
                                 
                             }];

From SenderFrame/NavigationItem, Menu With Images.

    [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:^{
                                 
                             }];

From SenderFrame/NavigationItem, Menu With Images, custom configuration.

    [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:^{
                                 
                             }];

From barButtonItems .

  • First: add action with event to you barButtonItems
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleDone target:self action:@selector(onNavButtonTapped:event:)]];
  • Second: implement the action, also supports custom configuration.
-(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:^{
                           
                       }];
}

CHANGELOG

CHANGELOG

More

  • Logo Designed by @Tobaloidee
  • Images in the demo from https://www.iconfinder.com/iconsets/pokemon-go.
  • If you like it, or maybe wanna use it in your own projects, please give me a star.
  • Looking for another way of doing this? Take a look at my another FTPopMenu at here. It was another way of showing pop over menus, which is wrapped from UIPopoverViewController, and more genetic and more good-looking. Feel free to try it.

License

FTPopOverMenu is available under the MIT license. See the LICENSE file for more info.

ftpopovermenu's People

Contributors

apozdeyev avatar deeer avatar flyandi avatar liufengting avatar yooomark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ftpopovermenu's Issues

Sometimes can't dismiss the menu

I meet a situation:
The menu show on the top of viewController, i can't touch the cell or the blank space to dismiss. But I can scroll the view below the menu.

The FTPopOverMenuConfiguration is like below:

    FTPopOverMenuConfiguration *configuration = [FTPopOverMenuConfiguration defaultConfiguration];
    configuration.menuRowHeight = 50;
    configuration.menuWidth = 200;
    configuration.borderWidth = 0;
    configuration.textFont = [UIFont systemFontOfSize:16];
    configuration.textColor = UIColor.blackColor;
    configuration.backgroundColor = [UIColor whiteColor];
    configuration.shadowColor = [UIColor clearColor];
    configuration.shadowRadius = 0;
    configuration.shadowOpacity = 0;
    configuration.shadowOffsetX = 0;
    configuration.shadowOffsetY = 0;
    configuration.ignoreImageOriginalColor = YES;

And the calling function is :

    [FTPopOverMenu showForSender:titleButton
                   withMenuArray:titles
                      imageArray:nil
                   configuration:configuration
                       doneBlock:^(NSInteger selectedIndex) {
                           /// do something
                       }
                    dismissBlock:nil];

无法在同一个页面同时显示多个弹出菜单?

看了一下,里面关于菜单的配置使用的是一个单例的configuration,显示菜单也是使用的单例menu。
建议考虑添加相互独立的menu菜单。可以保证在同一个页面弹出多个不同的菜单,而不同的菜单还可以有不同的样式(主要体现在背景色、文字颜色、宽度、高度等)。

为什么bar button item的需要传event的参数

使用文档里面写的 如果是 bar button item点击出来的pop,使用了show from event 方法,这个event 参数 有什么用,不是太懂,好像在item 的 action 方法里面 使用 show form sender view 也是可以的。

组件化依赖FTPopOverMenu出错问题

我公司项目的组件依赖FTPopOverMenu,但是作者的FTPopOverMenu.podspec没有声明s.ios.deployment_target = '9.0',这样在pod install安装后FTPopOverMenu项目的iOS Deploment Target为iOS 4.3,编译会出错,希望作者早日加上这个设置。

PS: 目前通过修改Podfile脚本解决

 post_install do |installer|
      installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
              config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] ='9.0'
          end
      end
  end

菜单高度计算问题

非常好的弹出菜单实现。
adjustPopOverMenu 里面计算高度没有用全局配置高度,会导致高度定制时候,总体高度不对。
另外,建议能实现直接传菜单图片数组,方便采用 FontAwesome。

能固定整个menu高度吗?

menu高度能固定吗,像tableview一样,能上下滑动的?

添加了一个menuShowDefaultRows属性。

// FTConfiguration
public var menuShowDefaultRows:Int = 0

    
fileprivate func configurePopMenuFrame() {
       //...
        if (arrowDirection == .Up) {
             popMenuFrame = CGRect(x: popMenuOriginX, y: (senderRect.origin.y + senderRect.size.height), width: configuration.menuWidth, height: popMenuHeight)
            if configuration.menuShowDefaultRows > 0 {
                let height = configuration.menuRowHeight * CGFloat(configuration.menuShowDefaultRows) + FTDefaultMenuArrowHeight
                 popMenuFrame = CGRect(x: popMenuOriginX, y: (senderRect.origin.y + senderRect.size.height), width: configuration.menuWidth, height: height)
            } 
        }
    }

.

Dismiss block calling

Hi

I am using checkmark tableview. But after click on row sometime Dismiss block calling instead of index selection. Please help

selectedCellBackgroundColor无效

看了下代码,设的值不对,应该把selectedCellBackgroundColor设为cell的backgroundView的backgroundColor。

还有个建议,cover呈现和消失的时候如果能有点过渡效果会更好,改编透明度的uiview动画也可以。

Out of screen

simulator screen shot 14 aug 2016 12 12 52

popup menu out of screen, is it possible to custom height for popup menu?
thank you

api建议

你这个做得很不错!但api属性不够灵活,属性命令应更贴近苹果的风格才好!
例如:
1,设置属性的不要用单例来控制,在不同界面有可能出现不同属性、色调;
2,FTPopOverMenuConfiguration应该当作一个属性来传;你现在这个如果我使用继承,在init去重设FTPopOverMenuConfiguration属性是无效,导致我每写一次都必须要跟着在+(void)show.....函数前写一大堆配置;
3,返回参数应该返回本类,然后可以通过返回实例再修改对应的popview属性;
4,我想改个背景色,这个情况下应该叫backgroundcolor更恰当,而不是tintColor;backgroundView这个背景颜色也没法改。

个人使用后的一些建议,谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.