开发者

How to click UIView Button of NavigationBar?

UIView *leftButtonItemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

UIImageView *addButtonEmptyImage = [[UIImageView alloc]init];
[addButtonEmptyImage setImage:[UIImage imageNamed:@"black.png"]];
addButtonEmptyImage.frame = CGRectMake(15,0,20,30);

[leftButtonItemView addSubview:addButtonEmptyImage];
[addButtonEmptyImage release];

UIImageView *correctButtonEmptyImage = [[UIImageView alloc]init];
[correctButtonEmptyImage setImage:[UIImage imageNamed:@"black.png"]];
correctButtonEmptyImage.frame = CGRectMake(50,0,20,30);

[leftButtonItemView addSubview:correctButtonEmptyImage];
[correctButtonEmptyImage release];

UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButtonItemView];
[leftButtonItemView release];

self.navigationItem.leftBarButtonItem = leftButtonItem;
[leftButtonItem release];

This is some source of my app. I know NavigationItem has two buttons(left and right). But I hope to make three buttons. so I make one button which use navigationItem and the other button which use a blank view. I want to click correctButtonEm开发者_开发知识库ptyImage. But this is in leftButtonItemView. namely, If I clicked the view which contains two images, I woud have seen leftButtonItemView not correctButtonEmptyImage. help me. thanks


Use UIButtons instead of UIImageViews as the subviews of your container view (leftButtonItemView). Use addTarget:action:forControlEvents: to assign action methods to the buttons.

PS: Please don't just say "It doesn't work" in your question. Tell us more specifically what works and what doesn't. Otherwise we won't be able to help you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜