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根據(jù)狀態(tài)不同變換顏色:
在button的點擊事件中寫:
[sender setSelected:!sender.isSelected];