在Interface Builder
中,我有一个带有文本"Explore the app“和UIImage
(>)的UIButton
,它看起来像这样:
[ (>) Explore the app ]
但我需要将此UIImage
放在文本后面:
[ Explore the app (>) ]
如何将UIImage
移到右侧?
发布于 2013-02-05 22:37:33
我对此的解决方案非常简单
[button sizeToFit];
button.titleEdgeInsets = UIEdgeInsetsMake(0, -button.imageView.frame.size.width, 0, button.imageView.frame.size.width);
button.imageEdgeInsets = UIEdgeInsetsMake(0, button.titleLabel.frame.size.width, 0, -button.titleLabel.frame.size.width);
发布于 2010-03-25 21:59:11
设置imageEdgeInset
和titleEdgeInset
以在映像中移动组件。您还可以使用这些全尺寸的图形创建一个按钮,并将其用作按钮的背景图像(然后使用titleEdgeInsets
移动标题)。
发布于 2011-09-19 09:30:54
Raymond W的答案在这里最好。具有自定义layoutSubviews的子类UIButton。非常简单,下面是一个为我工作的layoutSubviews实现:
- (void)layoutSubviews
{
// Allow default layout, then adjust image and label positions
[super layoutSubviews];
UIImageView *imageView = [self imageView];
UILabel *label = [self titleLabel];
CGRect imageFrame = imageView.frame;
CGRect labelFrame = label.frame;
labelFrame.origin.x = imageFrame.origin.x;
imageFrame.origin.x = labelFrame.origin.x + CGRectGetWidth(labelFrame);
imageView.frame = imageFrame;
label.frame = labelFrame;
}
https://stackoverflow.com/questions/2515998
复制相似问题