This property is used only for positioning the image during layout
其實titleEdgeInsets屬性和 imageEdgeInsets屬性只是在畫這個button出來的時候用來調(diào)整image和label位置的屬性,并不影響button本身的大小。
它們只是image和button相較于原來位置的偏移量,那什么是原來的位置呢?就是沒有設(shè)置edgeInset時候的位置了。
如果要image在右邊,label在左邊,那image的左邊相對于button的左邊右移了labelWidth的距離,image的右邊相對于label的左邊右移了labelWidth的距離
所以,self.oneButton.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);為什么是負值呢?因為這是contentInset,是偏移量,不是距離
同樣的,label的右邊相對于button的右邊左移了imageWith的距離,label的左邊相對于image的右邊左移了imageWith的距離
所以self.oneButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWith, 0, imageWith);
這樣就完成image在右邊,label在左邊的效果了。