Customize UIToolBar background image on iphone

I want to set a background image UIToolbarin an iPhone application.

I am currently setting up with UIColor initWithPatternImage:.

But that does not do what I want.

Please offer a different solution.

+3
source share
3 answers

Or you can create your own class and assign it to your control (via the interface builder) and inside which the drawRect method is implemented ...

like

- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"CustomImage.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
+3
source

You do not need to create a custom class. You can add UIToolBar category below

@implementation UIToolbar (UIToolbarCategory)
- (void)drawRect:(CGRect)rect {
    UIColor *color = [UIColor colorWithRed:0.547 green:0.344 blue:0.118 alpha:1.000]; //whatever goes well with your background image.
    UIImage *img  = [UIImage imageNamed: @"your-navbar-img.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [img release];
    self.tintColor = color;
    [super drawRect:rect];
}
@end

I tested and works well.

P.S: 4.3 , , , 4.2. , , .

4.3 UIToolbar UINavigationBar, . 4.3

#import <UIKit/UIKit.h>


@interface MyAppToolBar : UIToolbar{

}

@end

@implementation MyAppToolBar

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    UIColor *color = [UIColor colorWithRed:0.547 green:0.344 blue:0.118 alpha:1.000]; //wood tan color
    UIImage *img  = [UIImage imageNamed: @"your-navbar-img.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [img release];
    self.tintColor = color;

}

@end

, UIToolbar, XIB . , , UIImagePickerController .

+4
+1

Source: https://habr.com/ru/post/1741558/


All Articles