我有一个由3个按钮编程创建的工具栏(这里只有1个按钮)。经过大量的谷歌搜索,我能够设置一个很好的背景图片,但现在我不知道该放在哪里
action: target:self action:@selector(pressButton3:)方法的代码。所以我有一个漂亮的彩色图像的非工作按钮。我试过很多例子,如果按钮起作用,图像就不起作用,反之亦然。请帮帮忙。
//Add buttons
UIImage *buttonImage = [UIImage imageNamed:@"mapp.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithCustomView:button];
[systemItem1 initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(pressButton1:)];
//add to array
NSArray *items = [NSArray arrayWithObjects: systemItem1, nil];发布于 2011-08-02 12:47:10
我认为你的按钮应该可以工作,如果你添加:
[button addTarget:self action:@selector(pressButton1:) forControlEvents:UIControlEventTouchUpInside];然后删除这一行:
[systemItem1 initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(pressButton1:)];https://stackoverflow.com/questions/6325393
复制相似问题