首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >iPhone UIButton -图像位置

iPhone UIButton -图像位置
EN

Stack Overflow用户
提问于 2010-03-25 21:44:05
回答 12查看 87.4K关注 0票数 122

Interface Builder中,我有一个带有文本"Explore the app“和UIImage (>)的UIButton,它看起来像这样:

[ (>) Explore the app ]

但我需要将此UIImage放在文本后面:

[ Explore the app (>) ]

如何将UIImage移到右侧?

EN

回答 12

Stack Overflow用户

发布于 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);
票数 163
EN

Stack Overflow用户

发布于 2010-03-25 21:59:11

设置imageEdgeInsettitleEdgeInset以在映像中移动组件。您还可以使用这些全尺寸的图形创建一个按钮,并将其用作按钮的背景图像(然后使用titleEdgeInsets移动标题)。

票数 86
EN

Stack Overflow用户

发布于 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;
}
票数 54
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2515998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档