Giter Club home page Giter Club logo

lgbutton's Introduction

logo

build platform license Version

A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.

Preview

You'll be able to create buttons like these by using only the interface builder:

preview

Moreover you can use them for asynchronous operations.

async

Install

To integrate LGButton into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

pod 'LGButton'

Icons and images

You can add images/icons to your button, icons are taken from different ready to use font icons collections, images can be imported directly from your project assets folder.

You can customise icons/images on the left and/or on the right of the button title.

Icons

Icons are managed by SwiftIconFont integration, so you can easily add and customise button icons by choosing from the most popular font icons collections. In particular:

Collection Font name Cheat Sheet
Font Awesome fa List
Ion Icons io List
Octicons oc List
Open Iconic ic List
Material Icon ma List
Themify ti List
Map Icons mi List

The main properties that you need to set in order to use font icons are:

  • Icon Font Name: you can pick one value from the table above, different values will be ignored (please consider that not all the icons may be available since this library may not be updated right after a font library update).

  • Icon String: the icon name taken from the cheatsheet without the collection prefix.

So, if you want to use fa-align-left from Font Awesome, Icon Font Name will be fa and Icon String will be align-left.

Images

Set the Image source property in order to use an image from your assets folder.

Note: if Image source is set, every other property about the font icon on the same side will be ignored.

Usage

Drag and drop an UIView object into your view controller and set its class and module to LGButton.

class

Customise your button by setting the properties from the Interface Builder.

properties_1 properties_2

Supported Attributes

Attribute Description Default value
Bg Color Main background color clear
Show Touch Feedback Whether a touch feedback should be visible or not true
Gradient Start Color The first color of the gradient background nil
Gradient End Color The second color of the gradient background nil
Gradient End Color The second color of the gradient background nil
Gradient Horizontal Whether the gradient should be horizontal or not false
Gradient Rotation Set the gradient rotation angle (degrees from -360 to 360) 0
Corner Radius The corner radius 0.0
Fully Rounded Corners Apply a corner radius equals to height/2 false
Border Color The border color white
Border Width The border width 0.0
Title Color The title color white
Title String The title string EMPTY_STRING
Title Font Name The title font name nil
Title Font Size The title font size 14.0
Vertical orientation If true the left icon will be placed on the top and the right icon will be placed on the bottom false
Left Icon String The name of the left icon (taken from the cheat sheet) EMPTY_STRING
Left Icon Font Name The name of the left icon font name (taken from the table above) EMPTY_STRING
Left Icon Font Size The left icon font size 14.0
Left Icon Color The left icon color white
Left Image Src The name of the left source asset nil
Left Image Height The left image height 20.0
Left Image Width The left image width 20.0
Left Image Color The left image tint color nil
Right Icon String The name of the right icon (taken from the cheat sheet) EMPTY_STRING
Right Icon Font Name The name of the right icon font name (taken from the table above) EMPTY_STRING
Right Icon Font Size The right icon font size 14.0
Right Icon Color The right icon color white
Right Image Src The name of the right source asset nil
Right Image Height The right image height 20.0
Right Image Width The right image width 20.0
Right Image Color The right image tint color nil
Spacing Title Icon The spacing between the title and the image/icon 16.0
Spacing Top The internal top spacing 8.0
Spacing Bottom The internal bottom spacing 8.0
Spacing Leading The internal leading spacing 16.0
Spacing Trailing The internal trailing spacing 16.0
Shadow Offset The shadow offset (0,0)
Shadow Radius The shadow radius 0.0
Shadow Opacity The shadow opacity 1.0
Shadow Color The shadow color black
Loading spinner Color The loading spinner color white
Loading String The loading message text EMPTY_STRING
Loading Font Name The loading message font name EMPTY_STRING
Loading Font Size The loading message font size 14.0
Left Aligned true if the button items should be aligned to the left. It requires the button to have a fixed width false
Right Aligned true if the button items should be aligned to the right. It requires the button to have a fixed width false

You can download the demo project if you want to check more.

Issues

Feel free to submit issues and features requests.

Contributing

Contributions are more then welcome. Your contribution may include bug fixing or/and new features.

Please follow the "fork-and-pull" Git workflow (check here for more).

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that I can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Author

Lorenzo Greco

Credits

SwiftIconFont project is used in order to provide ready to use icons.

License

MIT License

Copyright (c) 2017 Lorenzo Greco

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.

lgbutton's People

Contributors

anarchoschnitzel avatar cdoky avatar gumbright avatar loregr avatar manucheri 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lgbutton's Issues

Transparent or non-opaque button backgrounds

Is there a way to make the button background transparent or non-opaque with alpha component less than 1? I pulled an IBOutlet into my VC as a UIView and attempted to set the backgroundColor to dark gray with alpha component 0.25 but that doesn't seem to work. Is it even possible?

Here's my code

@IBOutlet weak var cameraButton: UIView!
cameraButton.isOpaque = false
cameraButton.backgroundColor = UIColor.darkGray.withAlphaComponent(0.25)

Long compile times

Describe the bug
Is anyone else experiencing really long archive times for LGBUtton? I'm using v1.1.6 of the library, and this issue exists with v1.1.5 as well. I thought upgrading Xcode from 10.2 to 10.2.1 would fix it, as I assumed it was a bug with the Swift compiler, but the issue persists.

This only happens during the archive phase, with device set to "Generic iOS Device". And does not happen when simply building for a device

To Reproduce
Steps to reproduce the behavior:

  1. Create a new iOS UIKit project
  2. Create a Podfile with LGButton (you can use the sample I pasted below, as that's what I used to test)
  3. Run Pod update/install to get the latest version
  4. Open workspace, set device to "Generic iOS Device" and hit the archive button
  5. Watch that the compiler is stuck compiling LGButton

Expected behavior
Archive should not take long to archive the LGButton library. This is not a project or app specific issue, as I experienced this in a brand new project.

Desktop (please complete the following information):

  • OS: macOS 10.4.4

Smartphone (please complete the following information):

  • Device: Generic iOS Device
  • Xcode: 10.2 and 10.2.1

Additional context
Add any other context about the problem here.

platform :ios, '12.0'
use_frameworks!
# ignore all warnings from all pods
inhibit_all_warnings!

target 'Testing' do

pod 'LGButton'

end

Vertical alignment for image and title

Nice UIControl !!

Just missing Vertical alignment for image and title. Like this.
screen shot 2017-06-20 at 8 29 25 am

I know It can be fix using titleEdgeInsets & imageEdgeInsets, but it would be great if control have this functionality too.

Thanks.

addGestureRecognizer don't work

Describe the bug
Aftet update to last version, i can't add gesture recognizer in referenced buttons.

To Reproduce

 override func viewDidLoad() {
///..
 let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleButton))
 self.button.addGestureRecognizer(tap)
 self.button.isUserInteractionEnabled = true
///..
}
 @objc func handleButton() {
        self.dismiss(animated: true, completion: nil)
    }

Expected behavior
I need add touch button action from code because is dynamic.

Smartphone (please complete the following information):

  • Device: All
  • Version Last
  • Swift 5

pod install not working

Added to pod as

pod 'LGButton'

But keep getting this error upon pod install

[!] Unable to find a specification for 'LGButton'

Swift 3, Xcode 8

Updated google plus icon

How do I get the updated google plus icon from font awesome? When I set the corresponding values to fa and google-plus-g, I don't see the updated Google Plus.

Any help would be much appreciated! Thanks!

Spacing title icon doesn't work

When I put a left icon (string:camera, font: io) and a title string, they are both at the opposite of the UIView. Icon is at the extreme left and text at the extreme right. Setting "Spacing title icon" doesn't allow me to bring them closer, only "Spacing leading" and "Spacing trailing" change something.

PS: My LGButton is in a stackview with trailing constraints.

capture d ecran 2017-08-15 a 14 42 43

Modify disabled colour

Can you make it so that we can define what the button will look like when its disabled?
Right now the enabled and disabled button look extremely simular.

Add IBAction for Button

I create LGButton IBAction method, But not performing any action which, if your hold that button form a minute then it perform IBAction function.
It happen in one touch like normal button

AutoLayout errors show up

A lot of AutoLayout errors show up after adding LGButton to a view hierarchy which had no AutoLayout errors or warnings before, and even in a setup with only one single button as unique subview

Xcode 9.3 rendering error

Since Xcode 9.3 I get rendering errors with LGButton and that even makes most of my views invisible in Storyboard! Here is the error:

error: IB Designables: Failed to render and update auto layout status: dlopen(LGButton.framework, 1): no suitable image found.  Did find:
	LGButton.framework: required code signature missing for 'LGButton.framework'

border looks not good!

I want the border color is white, and the superview background is white too. It looks not good! How to solve this issue?
screen shot 2018-06-14 at 6 37 08 pm

Can you have a statically sized button and center the icon and title?

Is it possible to have a statically defined width (or one constrained by autolayout) and have the title and icon/image centered in the middle of the button? Right now, it looks like if I use autolayout or statically define a button size, that the title and icon will be aligned to the button edges.

Make LGButton open, so subclassable ?

For example, we need to patch some handy instance functions for the button, I would naturally think we can subclass it, then we can use the shared handy function everywhere, and make UI configs consistent

sth like:

clsss CustomButton: LGButton {
     init(withButtonTitle){
         super.init()
          // custom config
          // ....
     }
    
      func enableButton() {
          self.isEabled = true
          // other custom UI change to enabled button
          // ...
       }
       func disableButton() {
          // counterpart to enableButton.
        }
        
         //.. other functions needed per custom requirements
}

rootView added as a subview twice

xibSeup is called twice, first from init then later from awakeFromNib, resulting in the rootView being added twice to the view hierarchy.

Update for Swift 4.2 in pod

Hello,
I was just going to send a pull request for updating to swift 4.2 but i noticed the source code is on swift 4.2 only the update hasn't been delivered to cocoapods. So if you could, please bump your version with new changes you have already made.

Thanks in advance

Carthage support

In addition to CocoaPods I think Carthage support would be nice to have.

I might have time to help implement this in the future, but submitting an issue now in case someone feels up to the task.

Carthage info: https://github.com/Carthage/Carthage

I think the only thing that needs to be changed is making the schemes for building the framework 'shared'.

Releases are already tagged according to SemVer, which Carthage will respect automatically, so that is already done.

WOFF2 support

Have you tried using WOFF2 assets instead of TTF/OTF ? File-size is reduced greatly (asset folder goes from 897KB to 282KB)

There's no real info about official support other than the announcement in Safari's patch notes (WOFF2 works in iOS >= 10). Adding support for WOFF2 (with WOFF fallback for earlier iOS versions) is quite simple since it only required modifying a single line of code

Maybe push it as a new sub-spec ?

Still get black border arounded rounded image

Describe the bug
#33

To Reproduce
Steps to reproduce the behavior:
Round a button fully
add a white border
voila
the circle has a black very thin border

This is the same issue reported in issue 33, was this resolved?

Tap gesture conflict

I use an IBAction with event "Touched up inside" and my view controller has also a UITapGestureRecognizer. When I touch my button the IBAction is not called because the tap gesture prevail. That is not the case with a UIButton.
I found that some UIControl functions setting the Hilighted property are override in the LGButton class and that is not the case in UIButton class.

The solution I used is to use my view controller as a delegate of my gesture recognizer and to check if the location of the tap is inside my button bounds.

Error

A lot of errors in pod files. SwiftIconFont.Swift and Fontloader.swift have some error

Please add Carthage support

This is a popular dependency manager, many use it. You have a good library, it is a pity that it does not yet support installation via Carthage.

change button title

thanks for your pod.
I use it in my app but when I want change button title by this code:
buyBtn.titleString = "play"

buyBtn is outlet from lgButton that I use in my view controller
but app crash with this error :
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

pod install version 1.1.2

Add here your question
just find out there is version 1.1.5 to fix some touch bugs. which are present in my project
how can i update to 1.1.5

Centered Vertical Button

Is it possible to configure centered vertical button?
When I set it up the image goes to the top and the text goes to the bottom.

adjustFontToFitWidth

Is there anyway to force the title label to use adjustFontToFitWidth if it doesn't fit in the space? Would like the icon(s) to take priority, then the font size decreases based on how much space is left for the text label

Bug on tap action

After updating from 1.0.5 to 1.1.1, I need to hold the button to receive the IBAction in my view controller instead of just tap the button. I tested some things and found that if you remove the "if" of line 708 of file "LGButton.swift" (based on commit 3dfd991), the problem will no longer exists.

Support setting NSAttributedString as title

It would be nice if we can also set NSAttributedString as button title. In one of my project, I created all buttons programmatically and wanted to set NSAttributedString for some of them.

LGButton's gradients or background color does not change

Describe the bug
Depending on a flag, I want to change the gradient colors (Or, background color) of an LGButton. But, we cannot change the colors runtime from whatever the colors the button is initially initiated with or given on storyboard.

To Reproduce
Steps to reproduce the behavior:

  1. Drag an UIView onto any UIViewController's UIView or another UIView.
  2. Make it an instance of LGButton and assign an IBOutlet
  3. Assign them two gradient colors or just background color.
  4. Have a piece of code something like shown below to have new gradient colors.
  5. Check if new gradients are applied to the lgButton.
if status == true {
    lgButton.gradientStartColor = .red
    lgButton.gradientEndColor = .green
} else {
    lgButton.gradientStartColor = .gray
    lgButton.gradientEndColor = .white
}

Smartphone (please complete the following information):
iOS 12, 11

Preview dissapears from Storyboard

Hi, i was designing a view in the story board when I opened again XCode all the Buttons, are not visible. They are still there, but I can´t view then in the Storyboard.

Left Align Content

I was just wondering how to left align the content of the button, I can not get it working. This is the code I am using, with auto layout constaints to fill the button to a set width.

    let test: LGButton = {
        let lg = LGButton()
        lg.leftIconFontName = "io"
        lg.leftIconColor = UIColor.brandWhite
        lg.leftIconString = "social-youtube"
        lg.titleFontName = "AvenirNext-Bold"
        lg.leftIconFontSize = 18
        lg.titleFontSize = 18
        lg.cornerRadius = 16
        lg.titleString = "Show video"
        return lg
    }()

As you can see in the image below, the title is right aligning and if I set the spacingLeading or the spacingTrailing the all the content just centres when I would like it to be left aligned.

Imgur
I am aiming for it to look like this (Have not set the right font sizes or colours yet):
Imgur

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.