自定義導航欄上的按鈕

UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 15, 40, 40)];
    
    leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [leftButton setTitleColor:UIColorFromRGB(0x19191a) forState:UIControlStateNormal];
    [leftButton setTitle:@"帳單" forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(didList:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarButtonItems = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    
    UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                   target:nil action:nil];
//    nagetiveSpacer.width = -15;//這個值能夠根據本身須要本身調整
    self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftBarButtonItems];
相關文章
相關標籤/搜索