我为导航栏制作了至少10个按钮,但它似乎无法正常工作。 圆形边缘变得像素化。我不能在一个应用程序中,所以有谁能告诉我如何制作一个看起来像苹果的好图标?适当的尺寸是多少?应用程序中按钮的代码是
UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
backbtn.frame = CGRectMake(0, 0, 55, 30);
[backbtn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[backbtn addTarget:self action:@selector(goBackOne) forControlEvents:UIControlEventTouchUpInside]; forState:UIControlStateNormal ];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbtn];//set new button
self.navigationItem.hidesBackButton = YES;//hide original back button
答案 0 :(得分:0)
试试这段代码:
UIImage *backButtonImage = [UIImage imageNamed:@"backButton.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
[backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBackBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = customBackBarItem;
,后面的方法:
-(void)back {
[self.navigationController popViewControllerAnimated:YES];
}
上面的代码只是将图像设置为正常状态。您还可以设置突出显示状态以获得更好的外观。添加一些代码如:
UIImage *backButtonImageHighlighted = [UIImage imageNamed:@"backButtonHighlighted.png"];
[backButton setImage:backButtonImageHighlighted forState:UIControlStateHighlighted];