The Uitoolbar style of the iOS system is simple and often does not meet the needs of development or special purpose, such as setting a full background transparent uitoolbar or customizing the Uitoolbar background color, this time the Uitoolbar must be customized separately.
Set Uitoolbar background transparent, only need to set Uitoolbar backgroundcolor to [Uicolor Clearcolor], if you need to customize the Uitoolbar background color, You need to inherit and implement the Uitoolbar object yourself.
To modify the background color directly please refer to Method 2 for the following method 1, inheriting and implementing the Uitoolbar object yourself.
Method 1
The code is as follows |
Copy Code |
Align the button's tint color with the navigation bar Toolbar.tintcolor = Self.navigationController.navigationBar.tintColor; Toolbar.backgroundcolor = [Uicolor Clearcolor]; Set as background transparent For (UIView *view in [Righttoolbar Subviews]) { if ([View Iskindofclass:[uiimageview class]]) { [View Removefromsuperview]; } } |
Method 2
The code is as follows |
Copy Code |
//mytoolbar.h @interface mytoolbar:uitoolbar @end //mytoolbar.m @implementation Mytoolbar &NBSP -(ID) initWithFrame: (CGRect) arect { if ((self = [Super Initwithframe:arect]) { &NB sp; self.opaque = NO; self.backgroundcolor = [Uicolor clearcolor]; //set to background transparent, You can set the background picture here //self.backgroundcolor = [Uicolor colorwithpatternimage: [UIImage imagenamed:@ "background"]]; self.clearscontextbeforedrawing = YES; return self; } -(void) DrawRect: (cgrect) rect { //Do nothing } @end /td> |