Ios4 创建工具栏按钮的背景图像
我是iphone新手…我已经创建了带有四个按钮的工具栏…代码正在显示 下面…我想为每个按钮添加背景图像。有人帮我做这个吗Ios4 创建工具栏按钮的背景图像,ios4,Ios4,我是iphone新手…我已经创建了带有四个按钮的工具栏…代码正在显示 下面…我想为每个按钮添加背景图像。有人帮我做这个吗 TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)]; [toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent toolbar.tr
TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent
toolbar.translucent = YES;
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
UIBarButtonItem *Messages = [[UIBarButtonItem alloc] initWithTitle:@"About Me" style:UIBarButtonItemStyleBordered target:self action:@selector(currentuserdetails:)];
[buttons addObject:Messages];
[Messages release];
UIBarButtonItem *sendMessageBtn = [[UIBarButtonItem alloc] initWithTitle:@"Send Message" style:UIBarButtonItemStyleBordered target:self action:@selector(sendMessage)];
[buttons addObject:sendMessageBtn];
[sendMessageBtn release];
UIBarButtonItem *blockBtn = [[UIBarButtonItem alloc] initWithTitle:@"Block" style:UIBarButtonItemStyleBordered target:self action:@selector(blockcurrentuser:)];
[buttons addObject:blockBtn];
[blockBtn release];
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent
toolbar.translucent = YES;
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
UIBarButtonItem *Messages = [[UIBarButtonItem alloc] initWithTitle:@"About Me" style:UIBarButtonItemStyleBordered target:self action:@selector(currentuserdetails:)];
[buttons addObject:Messages];
[Messages release];
UIBarButtonItem *sendMessageBtn = [[UIBarButtonItem alloc] initWithTitle:@"Send Message" style:UIBarButtonItemStyleBordered target:self action:@selector(sendMessage)];
[buttons addObject:sendMessageBtn];
[sendMessageBtn release];
UIBarButtonItem *blockBtn = [[UIBarButtonItem alloc] initWithTitle:@"Block" style:UIBarButtonItemStyleBordered target:self action:@selector(blockcurrentuser:)];
[buttons addObject:blockBtn];
[blockBtn release];
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
对每一个都这样做,并像这样定制它们
UIImage *image = [UIImage imageNamed:@"audio-off.png"];
UIButton *myMuteButton = [UIButton buttonWithType:UIButtonTypeCustom];
myMuteButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[myMuteButton setImage:image forState:UIControlStateNormal];
[myMuteButton addTarget:self action:@selector(mute) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myMuteBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myMuteButton];
[buttons addObject:myMuteBarButtonItem];
[myMuteBarButtonItem release];