IOS create Uitoolbar with background transparency or a custom picture

Source: Internet
Author: User

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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.