举个例子
我们首先设置一个,button他的大小是宽90, 高90
UIButton *wcLoginButton = [UIButton buttonWithType:UIButtonTypeCustom];
wcLoginButton.backgroundColor = [UIColor redColor];
wcLoginButton.frame = CGRectMake(CGRectGetMidX(sdkLoginView.frame)-45, 10, 90, 90);
[wcLoginButton setImage:[UIImage imageNamed:@"XXX"] forState:(UIControlStateNormal)];
wcLoginButton.imageView.backgroundColor = [UIColor greenColor];
[wcLoginButton setTitle:@"微信" forState:(UIControlStateNormal)];
wcLoginButton.titleLabel.backgroundColor = [UIColor whiteColor];
wcLoginButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[wcLoginButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
wcLoginButton.titleLabel.font = [UIFont systemFontOfSize:13];
// button标题的偏移量
wcLoginButton.titleEdgeInsets = UIEdgeInsetsMake(wcLoginButton.imageView.frame.size.height+5, -wcLoginButton.imageView.bounds.size.width, 0,0);
// button图片的偏移量
wcLoginButton.imageEdgeInsets = UIEdgeInsetsMake(0, wcLoginButton.titleLabel.frame.size.width/2, wcLoginButton.titleLabel.frame.size.height+5, - wcLoginButton.titleLabel.frame.size.width/2);
[self.view addSubview:wcLoginButton];
以上仅代表个人观点,是个人在实际工作中实验出来的,如有不妥之处,各位大神指出。谢谢!