2015-01-20 113 views
-1

所以我一直在四處尋找並嘗試不同的代碼,我無法真正實現我想要的。我希望找到我在這裏尋找的東西。在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

回答

1

第一個問題是,我不能得到應用和取消按鈕有邊框。我該如何解決這個問題?

正如您所知,按鈕沒有邊框。所以沒有什麼可以「修復」。如果你堅持使用邊框,你必須自己繪製按鈕的背景圖像,使其看起來像一個邊框。這裏是我在一個我的應用程序中使用的一些代碼:

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

0

在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;