开发者

how set images on buttons of navigation bar?

开发者 https://www.devze.com 2023-03-14 18:40 出处:网络
I need to put images on add,cancel and back buttons of navigation bar. I have done with add button but not getting for back button.

I need to put images on add,cancel and back buttons of navigation bar. I have done with add button but not getting for back button.

even with this add button image it shows back blue color custom button.how to set for this?

UIBarButtonItem *addButton=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bar_add_button.png"] 
    style:UIBarButtonSystemItemAdd target:self               
    action:@selector(addNote)];  
开发者_如何转开发


// Initialize the UIButton
UIImage *buttonImage = [UIImage imageNamed:@"buttonImage.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);

// Initialize the UIBarButtonItem
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

// Set the Target and Action for aButton
[aButton addTarget:self action:@selector(aButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

// Then you can add the aBarButtonItem to the UINavigationBar
...
self.navigationItem.leftBarButtonItem = aBarButtonItem;

// Release buttonImage
[buttonImage release];
0

精彩评论

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