关于navigationitem leftbutton的size问题

当时想了很久的一个问题解决办法:
对于直接在barbuttonItem上加的uibutton是不能够改变尺寸大小:

    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"btn_back1"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    backBtn.frame = CGRectMake(0, 0, 40, 40);  //改不了尺寸,会被拉伸
    [backBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = barButtonItem ;

需将button加在一个UIView上,再将UIView加在barbuttonItem上,只需改变UIView的size即可:

UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
 UIButton *backBtn= [[UIButton alloc] initWithFrame:contentView.bounds];
 [backBtnsetImage:image forState:UIControlStateNormal];
 [contentView addSubview:backBtn];
  UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] contentView];
 self.navigationItem.leftBarButtonItem = barButtonItem ;

你可能感兴趣的:(关于navigationitem leftbutton的size问题)