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

2017-08-01  本文已影响26人  JohnayXiao
  
    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;

上一篇下一篇

猜你喜欢

热点阅读