2013-04-26 10 views
5

मैं अपनी यूआईटीयूएलबार की पारदर्शी पृष्ठभूमि (आईबुक के समान) बनाना चाहता हूं लेकिन मुझे translucent संपत्ति सेट करने के साथ कोई भाग्य नहीं है।यूआईटीूलबार की पृष्ठभूमि पारदर्शी कैसे बनाएं?

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
    NSMutableArray *toolBarItems = [[NSMutableArray alloc] init]; 
    [toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]]; 
    [toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Source" style:UIBarButtonItemStyleBordered target:nil action:nil]]; 
    [toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Aa" style:UIBarButtonItemStyleBordered target:nil action:nil]]; 
    [toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Rabbit" style:UIBarButtonItemStyleBordered target:nil action:nil]]; 
    toolBar.items = toolBarItems; 
    toolBar.translucent = YES; 
    [self.view addSubview:toolBar]; 

यह अभी भी इस तरह बाहर आता है:

यहाँ मेरी कोड है

enter image description here

+1

मुझे विश्वास है कि ऐसा करने के लिए आपको एक पारदर्शी पृष्ठभूमि छवि सेट करने की आवश्यकता होगी। बस एक 1x1 पिक्सेल पारदर्शी पीएनजी बनाएँ। – MTurner

+0

@ डौग स्मिथह uitoolbar के रूप में uiview का उप-वर्ग है, आप अल्फा –

+0

के मान को बदलकर इसे पारदर्शी बनाने के लिए इसकी परत संपत्ति का उपयोग कर सकते हैं: http://stackoverflow.com/questions/2468831/couldnt-uitoolbar- पारदर्शी # उत्तर -3253738 – Shad

उत्तर

23

यदि आप टूलबार चाहते हैं पारदर्शी:

[toolBar setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault]; 

और आप टूलबार पारभासी रूप चाहते हैं:

[toolBar setBarStyle:UIBarStyleBlack]; 
toolBar.translucent = YES; 

आशा है कि यह आप में मदद करता है।

+0

क्या आप पारदर्शी के लिए उपयोग की गई विधि को समझा सकते हैं? –

+1

पारदर्शी विधि अभी भी टूलबार सीमा के शीर्ष पर एक पतली बार दिखाती है, उससे कैसे छुटकारा पाएं? – Malloc

+1

आईओएस 7 –

2

एक विकल्प UIToolbar उपवर्ग और ड्रा विधि ओवरराइड करने के लिए है, बटन खुद को आकर्षित करने के लिए जारी रहेगा सामान्य के रूप में:

@interface TransparentToolbar : UIToolbar 
{ 
} 

@implementation TransparentToolbar 

// drawRect stub, toolbar items will still draw themselves 
- (void)drawRect:(CGRect)rect 
{ 
    return; 
} 

@end 
संबंधित मुद्दे