//在這個layoutSubviews中自定義你想要的位置
//這里是創(chuàng)建一個類,繼承自UIButton
#import "WWMarginButton.h"
@implementation WWMarginButton
- (void)layoutSubviews{
[super layoutSubviews];
[self.imageView makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.leading.equalTo(5);
}];
[self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.imageView.top);
}];
//這里的x 我自定義了x ww_x是frame.size.x
self.titleLabel.ww_X = CGRectGetMaxX(self.imageView.frame) + 10;
}
@end
以下這樣寫也是可以的

Snip20160720_8.png