导航栏添加自定义按钮(图片在左文字在右)

  
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addButton.frame = CGRectMake(10, 0, 60, 40);
    [addButton setImage:[UIImage imageNamed:@"iconfont-xinzengyemian"] forState:UIControlStateNormal];
    [addButton setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 25)];
    [addButton setTitle:@"新增" forState:UIControlStateNormal];
    [addButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 0)];
    [addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    addButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [addButton addTarget:self action:@selector(addButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    addButton.backgroundColor = [UIColor redColor];
    UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithCustomView:addButton];
    self.navigationItem.rightBarButtonItem = add;

你可能感兴趣的:(导航栏添加自定义按钮(图片在左文字在右))