Git Product home page Git Product logo

ayvibrantbutton's Introduction

AYVibrantButton

AYVibrantButton is a stylish button with iOS 8 vibrancy effect. It is a subclass of UIButton that has a simple yet elegant appearance and built-in support for UIVisualEffectView and UIVibrancyEffect classes introduced in iOS 8. Yet, it can be used on iOS 7 without the vibrancy effect.

Screenshot

Configurations

Vibrant buttons can be configured with one of the three supported button styles, invert, translucent and fill (see examples below).

Some basic properties like icon, text, font, alpha, corner radius, border width and background color (for no vibrancy effect) can all be changed easily.

The default vibrancy effect is for blur effect UIBlurEffectStyleLight. It could be set to any UIVibrancyEffect instance. For today extensions, it should be set to [UIVibrancyEffect notificationCenterVibrancyEffect].

Note

Though vibrant buttons can be placed anywhere, it is recommended that vibrant buttons with vibrancy effects should be placed in the contentView of UIVisualEffectView (except in today view).

UIVisualEffectView can be created as follows.

UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
effectView.frame = self.view.bounds;
[self.view addSubview:effectView];

Installation

CocoaPods

Add the following line to the Podfile.

pod "AYVibrantButton"

Manual Installation

Simply add AYVibrantButton.h and AYVibrantButton.m to your project.

Examples

The following images show the normal and highlighted (being pressed) button appearances.

Invert style with vibrancy effect

Invert Dark Invert Extra Light

Invert Dark Invert Extra Light

AYVibrantButton *invertButton = [[AYVibrantButton alloc] initWithFrame:CGRectZero style:AYVibrantButtonStyleInvert];
invertButton.vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
invertButton.text = @"Invert";
invertButton.font = [UIFont systemFontOfSize:18.0];
[effectView.contentView addSubview:invertButton];
```

### Translucent style with vibrancy effect

![Translucent Dark](https://github.com/a1anyip/AYVibrantButton/blob/master/Readme/translucent-dark.gif?raw=true)
![Translucent Extra Light](https://github.com/a1anyip/AYVibrantButton/blob/master/Readme/translucent-extralight.gif?raw=true)

````objective-c
AYVibrantButton *translucentButton = [[AYVibrantButton alloc] initWithFrame:CGRectZero style:AYVibrantButtonStyleTranslucent];
translucentButton.vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
translucentButton.text = @"Translucent";
translucentButton.font = [UIFont systemFontOfSize:18.0];
[effectView.contentView addSubview:translucentButton];
```

### Translucent style without vibrancy effect

![Translucent Dark](https://github.com/a1anyip/AYVibrantButton/blob/master/Readme/anycolor-dark.gif?raw=true)
![Translucent Extra Light](https://github.com/a1anyip/AYVibrantButton/blob/master/Readme/anycolor-extralight.gif?raw=true)

````objective-c
AYVibrantButton *button = [[AYVibrantButton alloc] initWithFrame:CGRectZero style:AYVibrantButtonStyleTranslucent];
button.vibrancyEffect = nil;
button.text = @"Any Color";
button.font = [UIFont systemFontOfSize:18.0];
button.tintColor = [UIColor blackColor];
[effectView.contentView addSubview:button];
```

## Changelog

### 1.0.4
* Added `invertAlphaHighlighted` property
* Changed the super class from `UIButton` to `UIControl`
* Changed `backgroundColor` to `tintColor`

### 1.0.3
* Added a new button style `AYVibrantButtonStyleFill`
* Fixed an issue that setting button alpha removes the vibrancy effect

### 1.0.2
* Support setting icon image

## Creator

**Alan Yip**
* [http://alanyip.me](http://alanyip.me)
* [@tweakcc](https://twitter.com/tweakcc)

## License
```
The MIT License (MIT)

Copyright (c) 2014 Alan Yip

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

ayvibrantbutton's People

Contributors

a1anyip avatar evildime 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

ayvibrantbutton's Issues

Invert style not working in ios 8

Hi there,
Pretty self-explanatory. But when I try using the invert style for a button, it doesn't work in ios8. Any ideas?
I tried removing the code for ios8 but unfortunately that also removes the title of the button itself.

Pixelated Button

Hello! I implemented this library but it looks like certain fill versions of the button come out pixelated. Any thoughts on why?

screen shot 2016-05-08 at 5 38 47 pm

screen shot 2016-05-08 at 5 39 05 pm

你好,这个导入项目用不了。。

  • (void)setCornerRadius:(CGFloat)cornerRadius {
    _cornerRadius = cornerRadius;
    [self.buttons.firstObject setCornerRadius:cornerRadius];
    [self.buttons.lastObject setCornerRadius:cornerRadius];
    }
    在这里会报错!

Font, title, and title color are not in line with UIButton behavior

AYVibrantButtons are gorgeous, but the non-standard button attributes are a huge drawback. Rather than an AYVibrantButton being a drop-in replacement for a UIButton, users must set the font, title, and title color properties in alternate ways. Worse, because of UIButton's default Auto Layout behavior, I end up having to set these attributes in BOTH the AYVibrantButton ways and the UIButton ways in order to get proper sizing behavior. I end up with code like this:
screen shot 2014-08-18 at 3 47 38 pm

It would be great if AYVibrantButton pulled these properties from the UIButton's standard implementation rather than providing its own, alternate properties.

Inheriting UIControl doesn't work...

When inheriting UIControl, you don't have these methods to call, so compilation fails:

self.font = self.titleLabel.font;
self.icon = [self imageForState:UIControlStateNormal];
self.text = [self titleForState:UIControlStateNormal];

You'll probably want to figure that out... unless something about my build settings is screwing it up?

Won't compile

Won't compile due to

 @import UIKit

it needs to be

  #import <UIKit/UIKit.h>

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.