按钮的文字居右
UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(rightButtonX, 0,rightButtonW , frame.size.height)];
//如果紧紧设置以下代码,不会生效
rightButton.titleLabel.textAlignment = NSTextAlignmentRight;
//需要加上这边这一行
rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
//如果不想让文字紧贴着边框,就加上下一行
rightButton.contentEdgeInsets = UIEdgeInsetsMake(0,0, 0, 10);
文字和图片的位置调换
CGRect rightButtonFrame = self.rightButton.frame;
self.rightButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 15);
self.rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, rightButtonFrame.size.width - 10, 0, 0);