开发者

Image is not getting added on UIBarButtonItem in iPhone

开发者 https://www.devze.com 2023-03-29 11:39 出处:网络
I am trying to add the image on to theUIBarButtonItem .But it is not getting added I don\'t what\'s going wrong in it this my code

I am trying to add the image on to the UIBarButtonItem .But it is not getting added I don't what's going wrong in it this my code

-(void)viewDidLoad
{
    UIToolbar *tools = [[UIToolbar alloc]
    initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)]; // 44.01 shifts it up 1px for some reason
        //tools.clearsContextBeforeDrawing = YES;
        //tools.clipsToBounds = YES;
        //tools.tintColor = [UIColor colorWithWhite:0.305f alpha:0.0f]; // closest I could get by eye to black, translucent style.
        // anyone know how to get it perfect?
        //tools.barStyle = -1; // clear background
        NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];

        // Create a standard refresh button.
        bi = [[UIBarButtonItem alloc]
        initWithImage:[UIImage imageNamed:@"map.png"] style:UIBarButtonItemStylePlain  target:self action:@selector(changeMapType:)];
        [buttons addObject:bi];
        [bi release];

        // Create a spacer.
        bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        bi.width = 12.0f;
        [buttons addObject:bi];
        [bi release];

        // Add profile button.
    开发者_StackOverflow中文版    bi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"map.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goToProfile)];
        bi.style = UIBarButtonItemStyleBordered;
        [buttons addObject:bi];
        [bi release];

        // Add buttons to toolbar and toolbar to nav bar.
        [tools setItems:buttons animated:NO];
        [buttons release];
        twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
        [tools release];
        self.navigationItem.rightBarButtonItem = twoButtons;
        [twoButtons release];
}

Thank you


You are creating your button as a UIBarButtonItemStylePlain, try:

UIBarButtonItem *button = [[UIBarButtonItem alloc] init];
[button setImage:[UIImage imageNamed:@"map.png"]];
0

精彩评论

暂无评论...
验证码 换一张
取 消