Git Product home page Git Product logo

apnumberpad's People

Contributors

dehlen avatar italika-git avatar kiancheong avatar podkovyrin avatar readmecritic avatar zackdotcomputer 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

apnumberpad's Issues

Carthage Support

I don't believe there is a framework configured, or a shared scheme to build the library using Carthage.

Set keyboard width

Hi, I know this is not an issue. I m using APNumberPad in iPad App and I want to know how can I set the keyboard width, just like the appearance of "Setting" App in iPad-->Touch ID & Password.

Updates to modernise the look of the number pad - rounded buttons for iOS15+

This is more informational than an issue. I hope some find it useful.

Thank you for this project. I was able to use it to replace a solution in a couple of 10-year-old apps whose keypads failed after a recent iOS update.

I offer the following method replacements to achieve a keypad that is closer in look to the current keypad with rounded buttons and, for my use cases, changed to place OK in the bottom left corner.
Please use if desired and/or update the base (with improved style as needed). I am not versed in SwiftPM, Cocoapods, Carthage etc. I used the code files from the zip download and modified as needed.

NumberPad example.pdf

In APNumberPadDefaultStyle.m

+ (CGRect)numberPadFrame {
    CGFloat safeAreaHeight = 0.0f;
    if (@available(iOS 13.0, *)) {
        UIEdgeInsets x = [[[UIApplication sharedApplication] windows][0] safeAreaInsets] ;
        safeAreaHeight = x.bottom;
    }
    if (safeAreaHeight > 0)
        return CGRectMake(0.0, 0.0, 320.0, 260.0);
    else
        return CGRectMake(0.0, 0.0, 320.0, 216.0);
}

+ (CGFloat)separator {
    return 6.0; //[UIScreen mainScreen].scale == 2.0 ? 6.0 : 6.0;
}

In APNumberPad.m

- (instancetype)initWithDelegate:(id<APNumberPadDelegate>)delegate numberPadStyleClass:(Class)styleClass {
    buttonsAdded = NO;
    self = [super initWithFrame:CGRectZero];
    if (self) {
        self.styleClass = styleClass;
        self.frame = [self.styleClass numberPadFrame];
//        self.autoresizingMask = UIViewAutoresizingFlexibleHeight; // for support rotation
        self.backgroundColor = [self.styleClass numberPadBackgroundColor];

        [self addNotificationsObservers];

        self.delegate = delegate;

        // Number buttons (0-9)
        //
        NSMutableArray *numberButtons = [NSMutableArray array];
        for (int i = 0; i < 11; i++) {
            APNumberButton *numberButton = [self numberButton:i];
//            [self addSubview:numberButton];
            [numberButtons addObject:numberButton];
        }
        self.numberButtons = numberButtons;

        self.safeAreaCover = [[UIView alloc] initWithFrame:CGRectZero];
        self.safeAreaCover.backgroundColor = [self.styleClass safeAreaSpaceColor];
        [self addSubview:self.safeAreaCover];

        // Function button
        //
        self.leftButton = [self functionButton];
        if (@available(iOS 15.0, *)) {
            UIButtonConfiguration *conf = _leftButton.configuration;
            NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"OK"];

            // Declare the fonts
            UIFont *titleFont1 = [APNumberPadDefaultStyle functionButtonFont];

            UIColor *titleColour1 = [APNumberPadDefaultStyle functionButtonTextColor];
            
            // Create the attributes and add them to the string
            [title addAttribute:NSFontAttributeName value:titleFont1 range:NSMakeRange(0,2)];
            [title addAttribute:NSForegroundColorAttributeName value:titleColour1 range:NSMakeRange(0,2)];
            conf.attributedTitle = title;

            _leftButton.configuration = conf;
            
        }
        else {
            self.leftButton.titleLabel.font = [self.styleClass functionButtonFont];
            [self.leftButton setTitleColor:[self.styleClass functionButtonTextColor] forState:UIControlStateNormal];
            [self.leftButton setTitle:@"OK" forState:UIControlStateNormal];
        }
        [self.leftButton addTarget:self action:@selector(functionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:self.leftButton];

        // Clear button
        //
        self.clearButton = [self functionButton];
        [self.clearButton setTitle:@"" forState:UIControlStateNormal];
        [self.clearButton setImage:[self.styleClass backspaceFunctionButtonImage] forState:UIControlStateNormal];
        [self.clearButton setImage:[self.styleClass backspaceFunctionButtonImageHighlighted] forState:UIControlStateHighlighted];
        [self.clearButton addTarget:self action:@selector(clearButtonAction) forControlEvents:UIControlEventTouchUpInside];

        UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc]
            initWithTarget:self
                    action:@selector(longPressGestureRecognizerAction:)];
        longPressGestureRecognizer.cancelsTouchesInView = NO;
        [self.clearButton addGestureRecognizer:longPressGestureRecognizer];
        [self addSubview:self.clearButton];
    }
    return self;
}

#pragma mark - Button fabric
- (APNumberButton *)numberButton:(int)number {
    APNumberButton *b = [APNumberButton buttonWithBackgroundColor:[self.styleClass numberButtonBackgroundColor]
                                                 highlightedColor:[self.styleClass numberButtonHighlightedColor]];
    if(@available(iOS 15.0,*))
    {
        UIButtonConfiguration *conf = b.configuration;
        NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:
                                            [NSString stringWithFormat:@"%d", number]];

        // Declare the font and colour
        UIFont *titleFont1    = [APNumberPadDefaultStyle numberButtonFont];
        UIColor *titleColour1 = [self.styleClass numberButtonTextColor];
        
        // Create the attributes and add them to the string
        [title addAttribute:NSFontAttributeName value:titleFont1 range:NSMakeRange(0,1)];
        [title addAttribute:NSForegroundColorAttributeName value:titleColour1 range:NSMakeRange(0,1)];
        conf.attributedTitle = title;

        b.configuration = conf;
    }
    else {
        [b setTitleColor:[self.styleClass numberButtonTextColor] forState:UIControlStateNormal];
        b.titleLabel.font = [self.styleClass numberButtonFont];
        [b setTitle:[NSString stringWithFormat:@"%d", number] forState:UIControlStateNormal];
    }
    return b;
}

In APNumberButton.m

+ (UIImage *)ap_imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0, 0.0, 1.0, 1.0);
    if(@available(iOS 15.0, *))
    {
        // Should work since iOS10 but doesn't in ios 14.5 simulator! - Godfrey
        UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat defaultFormat];
        format.scale = 1.0;
        UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:rect.size
                                                                                   format: format];
        
        UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
            [color setStroke];
            [context fillRect:rect];
        }];
        return image;
    }
    else
    {
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    }
}

- (instancetype)initWithBackgroundColor:(UIColor *)backgroundColor highlightedColor:(UIColor *)highlightedColor {
    self = [super initWithFrame:CGRectZero];
    if (self) {
        if (@available(iOS 15.0, *))
        {
            UIButtonConfiguration *conf = [UIButtonConfiguration filledButtonConfiguration];
            conf.cornerStyle = UIButtonConfigurationCornerStyleSmall;
            conf.baseForegroundColor = highlightedColor;
            conf.baseBackgroundColor = backgroundColor;
            // Create the attributed string
            NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:@" "];

            // Declare the fonts
            UIFont *titleFont1 = [UIFont fontWithName:@"Helvetica-Bold" size:10.0]; // place holder

            // Create the attributes and add them to the string
            [title addAttribute:NSFontAttributeName value:titleFont1 range:NSMakeRange(0,1)];
            conf.attributedTitle = title;
            self.configuration = conf;
        }
        else
        {
            [self setBackgroundImage:[UIImage ap_imageWithColor:backgroundColor] forState:UIControlStateNormal];
            [self setBackgroundImage:[UIImage ap_imageWithColor:highlightedColor] forState:UIControlStateHighlighted];
        }
    }
    return self;
}

Xcode 12.5 Beta 3 SPM: target 'APNumberPad' has invalid header layout: umbrella header found

Getting the following build error (Swift Package Manager):

target 'APNumberPad' has invalid header layout: umbrella header found at '~/Library/Developer/Xcode/DerivedData/collectors-cxrmmuolpcbfkpdnxggydzzxsvnh/SourcePackages/checkouts/APNumberPad/APNumberPad/APNumberPad.h', but directories exist next to it: ~/Library/Developer/Xcode/DerivedData/collectors-cxrmmuolpcbfkpdnxggydzzxsvnh/SourcePackages/checkouts/APNumberPad/APNumberPad/Assets, ~/Library/Developer/Xcode/DerivedData/collectors-cxrmmuolpcbfkpdnxggydzzxsvnh/SourcePackages/checkouts/APNumberPad/APNumberPad/Private; consider removing them

This error is new to Xcode 12.5. Everything works just fine in 12.4. The issue could be because of this change in 12.5:

Swift Packages
New Features

The Swift Package Manager now builds package products and targets as dynamic frameworks automatically, if doing so avoids duplication of library code at runtime. (59931771) (FB7608638)

Swift packages that specify a 5.4 tools version can now explicitly declare targets as executable, which allows the use of the @main keyword in package code. (SE-0294, 47691185)

Swift Package Manager caches package dependencies on a per-user basis, which reduces the amount of network traffic and increases performance of dependency resolution for subsequent uses of the same package. If needed, you can disable cache use in xcodebuild by using the new -disablePackageRepositoryCache flag. (72204929)

swift 3 syntaxe please !!

`// in .h:
#import <APNumberPad/APNumberPad.h>

@interface ExampleViewController : UIViewController

// in .m:

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.inputView = ({
APNumberPad *numberPad = [APNumberPad numberPadWithDelegate:self];
// configure function button
//
[numberPad.leftFunctionButton setTitle:@"Func" forState:UIControlStateNormal];
numberPad.leftFunctionButton.titleLabel.adjustsFontSizeToFitWidth = YES;
numberPad;
});

#pragma mark - APNumberPadDelegate

  • (void)numberPad:(APNumberPad *)numberPad functionButtonAction:(UIButton *)functionButton textInput:(UIResponder *)textInput {
    [textInput insertText:@"#"];
    }`

what is swift syntaxe for this

In swift APNumberpad delegate method is not calling

  • (void)numberPad:(APNumberPad *)numberPad functionButtonAction:(UIButton *)functionButton textInput:(UIResponder *)textInput {

}

this method is not calling in swift

private func numberPad(_ numberPad: APNumberPad, functionButtonAction functionButton: UIButton, textInput: UIResponder & UITextInput) {
print(textInput)

    textInput.insertText("#")

}

am using above code in swift..

Broken in iOS9 - Swfit 2.0

Converted my app to Swift 2.0 And APNumberPad no longer works. The actions are never fired.

       var pinPad: APNumberPad = APNumberPad(delegate: self)

---
    func numberPad(numberPad: APNumberPad!, functionButtonAction: UIButton!, textInput: UIResponder!) {
        var insertedPasswordhash: String = QueueMenuPinPad.text!
        if(insertedPasswordhash == Properties.Queue.Password){
            performSegueWithIdentifier("QueueMenu", sender: self)
        }else{
            DismisPinPad()
        }
    }

Delegate is nil.

`class DecimalNumberPad: APNumberPad {

convenience init() {
    self.init(delegate: DecimalNumberPadDelegate())
    leftFunctionButton.setTitle(".", for: .normal)
}

}`

`class DecimalNumberPadDelegate: NSObject, APNumberPadDelegate {

func numberPad(_ numberPad: APNumberPad, functionButtonAction functionButton: UIButton, textInput: UIResponder & UITextInput) {
    textInput.insertText(".")
}

}`

When I create delegate class, the delegate is nil when I click on left button.

It doesn't happen when I set delegate is viewcontroller

iPhone X compatibility

Hi, anyone out there still working on this? We really need some iPhone X compatibility. The keyboard is too low on the screen and is in the safe area. Thank you!

Having some trouble with the delegate call

I have the following code in a standard UIViewController class. I'm setting the APNumberPadDelegate to the class, and setting the delegate on the numberPad to self.

The keyboard appears fine and has the "X" on it as expected. But for some reason though the private func numberPad() delegate function isn't getting called. Any ideas why?

class WishListViewController: APNumberPadDelegate

`

let okAction = UIAlertAction(title: "Test", style: .default, handler: {(alert: UIAlertAction!) -> Void in
                  
    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {(alert: UIAlertAction!) -> Void in
      print("Cancel Pressed")
    })

    barcodeAlertView.addTextField(configurationHandler: {textField -> Void in

        let numberPad = APNumberPad(delegate: self)
        numberPad.leftFunctionButton.setTitle("X", for: .normal)
        textField.inputView = numberPad

        textField.textAlignment = .center
        textField.clearButtonMode = .whileEditing
    })

    barcodeAlertView.addAction(cancelAction)
    self.present(barcodeAlertView, animated: true, completion: nil)
}

`

private func numberPad(_ numberPad: APNumberPad, functionButtonAction functionButton: UIButton, textInput: UIResponder & UITextInput) {
    textInput.insertText("X")
}

`

Several second delay when run with debugger on iPad

I've been using APNumberPad in my project for a few months and it's generally great. However, I noticed that the first time I present my EditAmountViewController and load APNumberPad, there is a delay of about 10 seconds before the number pad appears. Subsequent instances of APNumberPad do not have a delay, until the app is run again. This problem only occurs when running the project on iPad.

Today, I downloaded the APNumberPad demo project and saw the same issue. I finally realized that this only occurs when running the project from Xcode with the debugger enabled. If I edit the Run scheme and deselect "Debug executable", the delay goes away.

I'm guessing this is related to Auto Layout, but not sure. Please fix it if possible so that others don't face the same confusion I have for the past few months.

Suggestion: Use UIKeyInput instead of UITextInput

Right now, the keyboard is taking on a lot of the logic of how the control should respond to a keypress. This isn't really the job of the keyboard - instead I think the keyboard should require conformance to UIKeyInput from the targeted view and just send it single key events using the insertText and deleteBackward methods.

Minimum Support Version

The project introduces the version after iOS 9, why can't I run on iOS 8, is there any problem?
Can you give points that need to be adapted iOS 8?

Hardware keyboard and APNumberPad

If a user uses an external keyboard (more applicable to iPad), is there a way to let number keystrokes on the keyboard fire the appropriate key buttons in APNumberPad?

CocoaPods issue with Xcode 14 beta

If APNumberPad is installed using CocoaPods, the workspace doesn't build with Xcode 14 beta (no problems with Xcode 13.4).

To reproduce, create an empty project with a Podfile:

target 'APNumberPadTest' do
  use_frameworks!
  pod "APNumberPad"
end

The error message is:

Signing for "APNumberPad-APNumberPad" requires a development team. Select a development team in the Signing & Capabilities editor. (in target 'APNumberPad-APNumberPad' from project 'Pods')

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.