我正在尝试幻灯片菜单。唯一的问题是UIButton的图像在运行时不显示。这是我编写的代码。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(NSString *)segueIdentifierForIndexPathInLeftMenu:(NSIndexPath *)indexPath
{
NSString *identifier;
switch (indexPath.row) {
case 0:
identifier=@"firstSegue";
break;
case 1:
identifier=@"secondSegue";
break;
}
return identifier;
}
-(void)configureLeftMenuButton:(UIButton *)button
{
CGRect frame = button.frame;
frame.origin=(CGPoint){0.0};
frame.size = (CGSize){40.40};
button.frame = frame;
[button setImage:[UIImage imageNamed:@"icon-menu"] forState:UIControlStateNormal];
}
我想您正在使用导航控制器。如果是这样,则实现可能如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureLeftMenuButton];
}
-(void)configureLeftMenuButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"icon-menu"] forState:UIControlStateNormal];
button.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
[button addTarget:self
action:@selector(yourAction:)
forControlEvents:UIControlStateNormal];
UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = menuItem;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句