如何设置元素的不同宽度 [iPhone-dev]
看这张图片:
用户名是 UIButton。如何在 UIButton(带有用户名)之后放置 UILabel(带有注释文本)?
UIButton 用户名是动态的。我该怎么做?
Look this pic:
The usernames are UIButton. How can I put a UILabel (with the comment text) just after the UIButton (with the username) ?
The UIButton username's is dynamic. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像一个
UITableView
,如果是这样的话,您应该子类化UITableViewCell
。如果不是,我会UITableViewCell
使其)包含 UIButton 和 UILabel,并根据标签动态定位文本内的文本按钮的大小(例如,在文本开头添加正确数量的空格)。That looks like a
UITableView
, if that's the case you should subclassUITableViewCell
. If it isn't, I wouldUITableViewCell
such that it) contains both a UIButton and a UILabel and dynamically position the text inside the label according to the size of the button (for instance, adding the right number of spaces to the beginning of the text).您将必须使用核心文本或 Web 视图来实现此目的。确实没有一个超级简单的方法可以做到这一点。根据计算的大小将视图彼此相邻放置很简单,但是要将文本换行为带有嵌入字体样式变化和附件(即图像)的多行,您将必须阅读 Core Text 或在 Web 视图中使用 XHTML。
You're going to have to use Core Text or web views to achieve this. There's really not a super easy way to do this. It's simple enough to place view next to each other based on their calculated sizes, but to have text wrap to multiple lines with embedded font style variations and attachments (i.e., images), you're going to have to read up on Core Text or use XHTML in web views.