1. 程式人生 > >ios導航欄rightBarButtonItems多個按鈕自定義設定

ios導航欄rightBarButtonItems多個按鈕自定義設定

ios導航欄rightBarButtonItems多個按鈕自定義設定 的方式有多種:

1.通過新增3個item中間的透明左邊和右邊顯示,來控制左右的間距

UIButton *informationCardBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    [informationCardBtn addTarget:self action:@selector(enterehzFilesVC:) forControlEvents:UIControlEventTouchUpInside];

    [informationCardBtn setImage:[UIImage imageNamed:@"TabBar1"] forState:UIControlStateNormal];

    [informationCardBtn sizeToFit];

    UIBarButtonItem *informationCardItem = [[UIBarButtonItem alloc] initWithCustomView:informationCardBtn];

    UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

    //控制左右按鈕的間距

    fixedSpaceBarButtonItem.width = 20;

    UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    [settingBtn addTarget:self action:@selector(enterTeamCard:) forControlEvents:UIControlEventTouchUpInside];

    [settingBtn setImage:[UIImage imageNamed:@"TabBars1"] forState:UIControlStateNormal];

    [settingBtn sizeToFit];

    UIBarButtonItem *settingBtnItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];

    self.navigationItem.rightBarButtonItems  = @[informationCardItem,fixedSpaceBarButtonItem,settingBtnItem];