如何在iPhone应用程序中实现UIButton / UILabel'填充' [英] How to achieve UIButton / UILabel 'padding' in iPhone app

查看:100
本文介绍了如何在iPhone应用程序中实现UIButton / UILabel'填充'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPhone应用程序中有各种视图需要填充,例如左边是文本对齐的自定义UIButton,背景颜色为UILabel。

I've got various views in my iPhone application that require padding e.g a custom UIButton with text aligned left, and a UILabel with a background color.

这可能是一个非常愚蠢的问题,但我如何应用'填充'来移动左边边的文本?

This may be a really stupid question, but how can I apply 'padding' to move the text off the left hand edge?

我已经厌倦了使用边界等没有任何成功。

I've tired using bounds etc without any success.

我知道我可以用背景颜色为我的 UILabel 创建一个包装器视图,但这似乎有些过分。

I know I could create a wrapper view for my UILabel with a background color, but it seems like overkill.

非常感谢。

推荐答案

好的最简单的解决方案我是到目前为止发现的是:

Ok the simplest solution I've found so far is:

self.textAlignment = UITextAlignmentCenter; 
[self sizeToFit]; 
CGRect frame = self.frame;
frame.size.width += 20; //l + r padding 
self.frame = frame;

不完全是我想要的,但它确实有效。

Not exactly what I wanted, but it works.

这篇关于如何在iPhone应用程序中实现UIButton / UILabel'填充'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆