首页 > 代码库 > UIKit学习之UIButton篇

UIKit学习之UIButton篇

1、应用场景,文字居左,图片居中

 //设置图片间距,使其居右对齐
btn.imageEdgeInsets = UIEdgeInsetsMake(0,btn.size.width - 12 - btn.imageView.image.size.width, 0, 0);
//文字居左对齐
 btn.titleEdgeInsets = UIEdgeInsetsMake(0, -(btn.imageView.image.size.width), 0, 0);
//设置文字居左且中心对齐
 [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
 [btn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

  

UIKit学习之UIButton篇