2012-09-21 36 views
0

如何重新創建顯示在SMS應用程序頂部的UIButtons(例如「加載早期消息」按鈕)。它們看起來像非常標準的UIButtons,除了有一個漸變,一個輕微的陰影陰影和內部陰影以及一個更藍的邊框。蘋果是否使用可伸縮的UIImage來製作這些或者它們是以編程方式創建的(以及如何)?SMS應用程序中的UIButton

enter image description here

+0

只需創建看起來像這樣的圖像資產並將它們用於按鈕的背景圖像。 –

+0

這是我的後備計劃。我喜歡儘可能以編程方式創建事物,但我不必擔心屏幕大小。 – jadengeller

+0

通常你會設計一個固定高度的按鈕,所以你只需要一些資產,而設計的圖片總是傾向於看起來更像一些這樣的東西。如果你想以編程方式創建它,你可以繪製形狀並使用'CGGradient'來填充它。 –

回答

1

我最喜歡的解決這個問題是創建恰好與一個段分段控制。你最終會看到一個漂亮的按鈕。以下是我如何以編程方式執行此操作:

UISegmentedControl* takePhotoButton = 
    [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Take Photo"]]; 
takePhotoButton.segmentedControlStyle = UISegmentedControlStyleBar; 
takePhotoButton.frame = CGRectMake(55,336,110,38); 
takePhotoButton.tintColor = [UIColor lightGrayColor]; 
NSDictionary *attributes = [NSDictionary dictionaryWithObject:[UIFont boldSystemFontOfSize:16] 
                 forKey:UITextAttributeFont]; 
[takePhotoButton setTitleTextAttributes:attributes 
           forState:UIControlStateNormal]; 
takePhotoButton.momentary = YES; 
[takePhotoButton addTarget:self 
        action:@selector(onTakePhoto:) 
      forControlEvents:UIControlEventValueChanged]; 
[self.view addSubview:takePhotoButton]; 
+0

雖然這確實是一個很好看的按鈕,但我正在尋找上面顯示的按鈕的確切複製。謝謝你的提示,但! – jadengeller

相關問題