UIButton 图片文字上下对齐

UIImage *buttonImg = [button imageForState:UIControlStateNormal];
CGFloat titleWidth = [button.titleLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:18],NSFontAttributeName, nil]].width;
[button setTitleEdgeInsets:UIEdgeInsetsMake(buttonImg.size.height, -buttonImg.size.width, 0, 0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(-15, 0, 0, -titleWidth)];

效果如下。俩个图不对称是因为图片大小不同。

posted @ 2015-02-27 10:50  NSFuck  阅读(1841)  评论(0编辑  收藏  举报