UIButton 图标与文字上下垂直对齐

    botton.imageEdgeInsets = UIEdgeInsetsMake(- (botton.frame.size.height - botton.imageView.frame.size.height)/2, 0, (botton.frame.size.height - botton.imageView.frame.size.height)/2, 0);
    
    botton.titleEdgeInsets = UIEdgeInsetsMake(0, - (botton.imageView.frame.size.width/2 + botton.titleLabel.frame.size.width/2), 0, (botton.imageView.frame.size.width/2 + botton.titleLabel.frame.size.width/2));

 

核心代码:

UIEdgeInsetsMake(top, left, bottom, right);

由于Y轴通过top、bottom控制,在设置偏移量的时候要同时修改,如只修改一边,则偏移量倍数要x2(X轴同解)

 

posted @ 2015-11-09 17:36  ly1992  阅读(583)  评论(0)    收藏  举报