iOS中UIButton的title和image的位置设置

一, 设置image在button上的位置, 属性是imageEdgeInsets

//设置image在button上的位置(上top,左left,下bottom,右right)
//这里可以写负值,对上写-5,那么image就象上移动5个像素
    self.shitidianButton.imageEdgeInsets = UIEdgeInsetsMake(0,33,16,33);
    self.zhiyingButton.imageEdgeInsets = UIEdgeInsetsMake(0,33,16,33);
    self.tianjieButton.imageEdgeInsets = UIEdgeInsetsMake(0,33,16,33);

二,设置title在button上的位置,属性是titleEdgeInsets

 //设置title在button上的位置(上top,左left,下bottom,右right)
    self.shitidianButton.titleEdgeInsets = UIEdgeInsetsMake(20,0, 0, 0);
    self.zhiyingButton.titleEdgeInsets = UIEdgeInsetsMake(20,0, 0, 0);
    self.tianjieButton.titleEdgeInsets = UIEdgeInsetsMake(20,0, 0, 0);

https://www.jianshu.com/p/b4cb35c41bf0

你可能感兴趣的:(iOS中UIButton的title和image的位置设置)