Giter VIP home page Giter VIP logo

mnfloatingactionbutton's Introduction

MNFloatingActionButton

A little iOS experiment, a Floating Action Button.

button gif

Installation

As Cocoapod https://cocoapods.org

pod 'MNFloatingActionButton', '~> 2,0'

Alternatively, add the images and .h &.m files to your project.

General Usage

Just like a normal button, you instantiate with a frame and add as a subview.

MNFloatingActionButton *button = [[MNFloatingActionButton alloc] initWithFrame:CGRectMake(0,0,50,50)];
[self.view addSubview:button];

As it is a subclass of UIControl, you can add a target to listen to touch events. The touch events that are sent are:

  • UIControlEventTouchUpInside
  • UIControlEventTouchCancel
[button addTarget:self action:@selector(createButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

You can also use MNFloatingActionButton in Storyboards and xibs by creating a UIView object and changing it's custom class to MNFloatingActionButton.

Customisation

There are currently 6 properties that you can modify to customise your button. They are:

  • centerImage - Set to nil if you don't want an image
  • backgroundColor - Defaults to some kinda blue
  • shadowColor - Defaults to the background color.
  • shadowOpacity - Default is 0.6f
  • shadowRadius - Default is 1.5f
  • animationScale - Set's the end size of button when pressed. Defaults to 0.85f
  • animationDuration - Defaults to 0.05f

Thanks

I did this because I thought it might be fun for people to play around with. If you like, or you don't like it, then help make it better with a PR!

mnfloatingactionbutton's People

Contributors

mattnydam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mnfloatingactionbutton's Issues

Allow image to be configurable

Would it be possible to give us a Setter for the image? I'm kinda just hacking it in there by deleting the subview and re-adding in an image right now :)

Wrong image position

Hi, I'm adding your button from code using autolayot, and when button appears, "+" image placed outside of button. Here is my code sample:

    _menuButton = [[MNFloatingActionButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

    [self.view addSubview:_menuButton];
    _menuButton.translatesAutoresizingMaskIntoConstraints = NO;
    NSDictionary *views = NSDictionaryOfVariableBindings(_menuButton);

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_menuButton(50)]-20-|"
                                                                                               options:0
                                                                                               metrics:nil
                                                                                                 views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_menuButton(50)]-20-|"
                                                                                               options:0
                                                                                               metrics:nil
                                                                                                 views:views]];

After pressing button, "+" image appears on right place

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.