在numberpad中添加边框到按钮上的按钮并在空白区域添加+符号

问题描述:

所以我一直在四处寻找并尝试不同的代码,我无法真正实现我想要的。我希望找到我在这里寻找的东西。在numberpad中添加边框到按钮上的按钮并在空白区域添加+符号

我想制作一个自定义数字键盘。这是我想要的结果:

enter image description here

但是,这是接近我得到。

​​

第一个问题是,我不能得到的应用和取消按钮有边框。我该如何解决这个问题?

第二个问题是我想在我的数字键盘上添加+ *#按钮。我到底该怎么做?

这是代码即时通讯与合作:

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; 
+0

如果有一个标题/图像是“”+ *#“'”的按钮, – matt 2015-01-20 19:11:58

+0

第一张照片是旧的iOS 6和之前的外观。底部图片是新的iOS 7及更新的外观。按钮不再有边框。 – rmaddy 2015-01-20 19:12:11

+2

使用电话型键盘而不是数字键盘键盘。 – rmaddy 2015-01-20 19:13:28

第一个问题是,我不能得到应用和取消按钮有边框。我该如何解决这个问题?

正如您所知,按钮没有边框。所以没有什么可以“修复”。如果你坚持使用边框,你必须自己绘制按钮的背景图像,使其看起来像一个边框。这里是我在一个我的应用程序中使用的一些代码:

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) 
+0

如果你有两个不相关的问题(你这样做),请问两个不同的问题。 – matt 2015-01-20 19:15:39

+0

Thnx,下次请记住 – 2015-01-20 19:32:26

在iOS 7中,默认的UIButton具有透明背景和无边框。在iOS7 +中,如果您想要iOS 6的边角和背景,请使用自定义按钮。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 

现在你可以设置背景,边框和角半径,如果你想。

button.layer.cornerRadius = 2.0f; 
button.layer.borderWidth = 1.0f; 
button.layer.borderColor = [UIColor whiteColor].CGColor; 
button.backgroundColor = [UIColor blueColor]; 
button.clipsToBounds = YES;