2013-05-06 54 views
1

看一看這個圖像...如何設置圖像的UIBarButtonItem靈活的空間 - IOS

enter image description here

我想設計工具欄這樣的,每一個的UIBarButtonItem應該用細線分開。所以我已經在每個UIBarButtonItem之間插入了靈活的空間按鈕(這可以幫助我在對齊UIBarButtonItem的同時改變方向),但是如果我爲它設置了一個圖像,那麼它就不會像更靈活的按鈕一樣,變爲普通的UIBarbutton。

所以我需要一個靈活的空間按鈕與圖像..任何想法如何做到這一點。 (OR) 如何設計一個UIToolbar像上面...任何幫助真的很感激。感謝名單

回答

0

要的UIBarButtonItem

UIImage *faceImage = [UIImage imageNamed:@"facebook.png"]; 
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom]; 
face.bounds = CGRectMake(0, 0, faceImage.size.width, faceImage.size.height); 
[face setImage:faceImage forState:UIControlStateNormal]; 
UIBarButtonItem *faceBtn = [[UIBarButtonItem alloc] initWithCustomView:face]; 
+0

它會工作,如果它是一個普通的UIBarButtonItem,它不適用於UIBarButtonItem靈活的空間按鈕。 – Newbee 2013-05-06 10:41:48

0

設置背景圖片,我認爲這將幫助你..

UIImage* topImage = [UIImage imageNamed:@"TabBarGradient.png"]; 

// Create a new image context 
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, topImage.size.height*2), NO, 0.0); 

// Create a stretchable image for the top of the background and draw it 
UIImage* stretchedTopImage = [topImage stretchableImageWithLeftCapWidth:0 topCapHeight:0]; 
[stretchedTopImage drawInRect:CGRectMake(0, 0, width, topImage.size.height)]; 

// Draw a solid black color for the bottom of the background 
[[UIColor blackColor] set]; 
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, topImage.size.height, width, topImage.size.height)); 

// Generate a new image 
UIImage* resultImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

return resultImage; 

和更詳細的您可以檢查此...

http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/

如果沒有解決你的問題..我知道..

+0

當然,我會盡力讓你知道。 – Newbee 2013-05-06 10:47:46

+0

@Newbee代碼可以幫助你嗎? – Shivaay 2013-05-13 06:08:11