-1

So I have been looking around and trying different codes and I cant really achieve what I want. I hope to find what I seek here.

I am trying to make a custom number pad. This is the result I want:

enter image description here

But this is as close I get.

enter image description here

First problem is that I cant get the apply and cancel button to have borders. How can i fix that?

The second problem is that I want to add the +*# button on my number pad also. how on earth can i do that?

This is the code im working with:

self.numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
self.numberToolbar.barStyle = UIBarStyleBlackTranslucent;
self.numberToolbar.items = [NSArray arrayWithObjects:
                            [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelNumberPad)],
                            [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                            [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
                            nil];
[self.numberToolbar sizeToFit];

self.driverNumber.inputAccessoryView = self.numberToolbar;
Hemang
  • 26,840
  • 19
  • 119
  • 186
Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45

2 Answers2

1

First problem is that i cant get the apply and cancel button to have borders. How can i fix that?

As you've been told, buttons do not have borders. So there is nothing to "fix". If you insist on borders, you will have to draw the background image of the button yourself, in such a way that it has something that looks like a border. Here is some code that I use in one my apps:

b.setBackgroundImage(imageOfSize(CGSizeMake(15,15)) {
    let grad = CAGradientLayer()
    grad.frame = CGRectMake(0,0,15,15)
    grad.colors = [
        UIColor(red: 1, green: 1, blue: 0, alpha: 0.8).CGColor,
        UIColor(red: 0.7, green: 0.7, blue: 0.3, alpha: 0.8).CGColor]
    let p = UIBezierPath(
        roundedRect: CGRectMake(0,0,15,15), cornerRadius: 8)
    p.addClip()
    grad.renderInContext(UIGraphicsGetCurrentContext())
    UIColor.blackColor().setStroke()
    p.lineWidth = 2
    p.stroke()
}.resizableImageWithCapInsets(
    UIEdgeInsetsMake(7,7,7,7), resizingMode: .Stretch),
    forState: .Normal)
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • And if you have two unrelated questions (you do), please ask two separate questions. – matt Jan 20 '15 at 19:15
0

In iOS 7 default UIButton is with transparent background and no borders. In iOS7+, If you want to have corners and backgrounds like iOS 6 use custom button.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

Now you can set background, border and corner radius if you want.

button.layer.cornerRadius = 2.0f;
button.layer.borderWidth = 1.0f;
button.layer.borderColor = [UIColor whiteColor].CGColor;
button.backgroundColor = [UIColor blueColor];
button.clipsToBounds = YES;
Babu Lal
  • 136
  • 1
  • 4