开发者

Changing UIBarButtonItem colors

开发者 https://www.devze.com 2023-01-01 18:59 出处:网络
This is a pretty simple question and I really can\'t find the answer! So okay, by default if I set the tintColor of a UIToolbar, the UIBarButtonItem\'s colors will be the same.

This is a pretty simple question and I really can't find the answer!

So okay, by default if I set the tintColor of a UIToolbar, the UIBarButtonItem's colors will be the same.

I only want to change the colors of my UIBarButtonItems and also change their text's colors.

Is there anybody out there having an idea on how to do so?

I really can't believe it is so complicated, really... changing an UIButton properties 开发者_运维知识库is so easy, I can't see why it's not the same for an UIBarButtonItem...

Thanks so much!


Not sure you found the answer. Here's how I do it:

UIImage *buttonImage = [[UIImage imageNamed:@"btnGreen.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
[doneButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];    
[doneButton addTarget:self action:@selector(saveDateEdit:) forControlEvents:UIControlEventTouchUpInside];
[doneButton.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
doneButton.frame = CGRectMake(0.0, 0.0, 50, 30);
btnDone = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
[doneButton release];
0

精彩评论

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

关注公众号