简体   繁体   English

如何使用自动布局/故事板在UIImage旁边截断UILabel?

[英]How can I truncate a UILabel next to a UIImage using autolayout/storyboard?

I have a UILabel next to a UIImage where I want the UILabel to be show truncated "..." if it starts to overlap with the neighboring UIImage. 我在UIImage旁边有一个UILabel,如果UILabel开始与相邻的UIImage重叠,则我希望该UILabel显示为“ ...”。

Text is behind the UIImage when i want it to just truncate: 当我想要截断文本时,文本位于UIImage的后面:

文字在图像后面

My UILabel properties: 我的UILabel属性: ui标签属性

My image properties: 我的图片属性: 图像属性

I thought the issue is the content compression but I set the UILabel's content compression resistant priority horizontal to 250 and the UIImage to 1000. This only hides the UILabel behind the UIImage. 我以为问题是内容压缩,但是我将UILabel的耐内容压缩优先级水平设置为250,将UIImage设置为1000。这仅将UILabel隐藏在UIImage后面。

*This is inside a table cell. *这在表格单元格内。 I'm not using the default table cell view because i intend to customize it further. 我没有使用默认的表格单元格视图,因为我打算进一步对其进行自定义。

从UILable到UIImage的尾随添加常量值5,并且关系小于和等于(<=)。

Three things can be done. 可以完成三件事。

  1. Provide a trailing space for the label to the image view. 为标签到图像视图提供尾随空间。 This will make sure that the label always gets truncated if text grows up. 这样可以确保如果文本变长,标签总是会被截断。
  2. Provide a trailing space for the label to the cell's content view with the constraint constant set to the image view plus margins, if any. 为标签提供到单元格内容视图的尾随空格,并将约束常量设置为图像视图加上边距(如果有)。
  3. Keep the current configuration but take an IBOutlet and set its preferred width(found in 2nd last tab of the navigator.) to the screen width minus the image width. 保持当前配置,但采用IBOutlet并将其首选宽度(在导航器的第二个选项卡中找到)设置为屏幕宽度减去图像宽度。 This will make sure that your label grows with the text but never exceeds the image. 这将确保您的标签随文本一起增长,但不会超出图像。

Add constraint between: 在以下之间添加约束:

1) UIImage and the table cell (the container view) 1)UIImage和表格单元格(容器视图)

2) UILabel and the UIImage 2)UILabel和UIImage

3) and finally one between tableCell and UILabel 3)最后是tableCell和UILabel之间的一个

This way you will have your UILabel stretching from the left side of the cell all the way to the image view, and truncate the text that doesnt fit into the label. 这样,您将使UILabel从单元格的左侧一直延伸到图像视图,并截断不适合标签的文本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Autolayout Xcode6将UILabel相对于Universal Storyboard中的UIImage定位 - Position UILabel relative to UIImage in Universal Storyboard using Autolayout Xcode6 如何使用AutoLayout使UIImage的高度与UILabel的固有高度相同? - How can I make my UIImage the same height as the intrinsic height of my UILabel using AutoLayout? 如何使用带有Storyboard的Autolayout获取UIView子类的框架? - How can I get the frame of a UIView subclass using Autolayout with Storyboard? 如何检测UILabel(不设置宽度,仅设置AutoLayout)是否被截断(您好,我是Test…)? - How to detect UILabel (without set width just AutoLayout) is truncate like (Hello I am Test…) or not? 如何使用情节提要板为不同的设备设置自动布局 - how to set autolayout for different devices by using storyboard 如何仅使用情节提要使 UILabel 的 UIView 超级视图适合 UILabel 的固有高度? - How do I make the UIView superview of a UILabel fit the intrinsic height of the UILabel using the storyboard only? 如何在iOS中截断UIImage - How to truncate a UIImage in iOS 使用自动布局的带有故事板的UIScrollView - UIScrollView with storyboard using autolayout AVCaptureVideoPreviewLayer:与情节提要和自动布局一起使用 - AVCaptureVideoPreviewLayer: using with Storyboard and Autolayout 使用AutoLayout以编程方式将多行UILabel的第一行与UIImage对齐(Objective-C) - Align first line of multiple lines UILabel with UIImage using AutoLayout programmatically ( Objective-C )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM