ios - UITableViewCell 中的标签,更改第二行字体大小,添加边距?

标签 ios swift

我有一个使用 UITableViewCell 并由来自 parse.com 的数据填充的表格 View 。在 UITableViewCell 中有一个包含 2 行的 LABEL,显示来自 parse.com 的数据。

我想知道是否可以更改 LABEL 第二行的字体大小(保持第一行的字体大小相同),还有没有办法在标签的左侧和右侧添加边距标签?

编辑:打错了,我想更改标签第二行的字体大小,以及在标签的左侧和右侧添加边距。

最佳答案

在我的解决方案中,我使用 UILabelattributedText 将属性字符串添加到标签

var attributedString = NSMutableAttributedString(string:"My first line \n")
//creating NSMutableAttributedString that will be later appended with your second line

var secondLine = "My attributed second line"
let secondLineAttribute = [NSFontAttributeName : UIFont(name: label.font.fontName, size: 22)!]
//replace 22 with the size of text you want for second line
var newAttributedSecondLine: NSAttributedString = NSAttributedString(string: secondLine, attributes: secondLineAttribute)
attributedString.appendAttributedString(newAttributedSecondLine)

label.attributedText = attributedString

不要忘记在上面的代码前加上label.numberOfLines=2

关于ios - UITableViewCell 中的标签,更改第二行字体大小,添加边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31955703/

相关文章:

ios - Parse中拉取PFUser.currentUser的指针域数据

ios - 重用UICell时如何刷新UITableView

ios - 将缩略图附加到通知时,文件去了哪里?

ios - 有两个选择的数组让我只完成了一半

android - 如何调整屏幕的纵向和横向模式,以便可以看到所有 UI 元素?

objective-c - 移动部分中的最后一行时 UITableView endUpdates 崩溃

android - 如何从 phonegap 上的服务器访问 Assets 资源

ios - 在父 UIViewController UIView 中以模态方式呈现 ViewController

swift - 在程序开始时,RealmSwift 现有对象的数量始终为 4

ios - iOS 8 和 iOS 7 的 UDID 替换