button的标题居左显示:
居左:
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
距左11:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 11, 0, 0);
将button布成左图片,右title的样式:
UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 45, 30);
[leftButton setImage:[UIImage imageNamed:@"position"] forState:UIControlStateNormal];
[leftButton setTitle:@"切换" forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(changeAddress:) forControlEvents:UIControlEventTouchUpInside];
leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
UIBarButtonItem * leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
self.navigationItem.leftBarButtonItem = leftButtonItem;
button根据状态不同变换颜色:
在button的点击事件中写:
[sender setSelected:!sender.isSelected];