简体   繁体   English

如何为UITableViewRowAction设置多行标题

[英]How to set multiline title for UITableViewRowAction

How can I split the title string of a UITableViewRowAction in two lines? 如何将UITableViewRowAction的标题字符串分成两行? ...like Apple has done it in their mail app (iPhone); ...就像Apple在他们的邮件应用程序(iPhone)中做到的那样; swipe right in the email list and you'll see the action "Mark as Unread", written on two lines. 在电子邮件列表中向右滑动,您将看到两行写的“标记为未读”操作。

Thanks a lot! 非常感谢!

I never received a response on the comment so I'll assume you tried it and it worked. 我从未收到过评论的回复,所以我假设你尝试了它并且它有效。 Regardless, the answer is to simply add a newline character to your title string. 无论如何,答案是简单地在标题字符串中添加换行符。 The title of a UITableViewRowAction is multiline compat. UITableViewRowAction的标题是多行compat。

var buttonTest = UITableViewRowAction(style: UITableViewRowActionStyle.Default, 
    title: "Line1\nLine2", handler: { (action, indexPath) -> Void in

If you want to customize the edit actions beyond the scope of what Apple allows you could always write your own functions that do the same thing or even use a library such as THIS to accomplish the same thing. 如果你想要自定义超出Apple允许范围的编辑操作,你总是可以编写自己的函数来做同样的事情,甚至使用像THIS这样的库来完成同样的事情。 This is what we were doing before Apple released the action to the public. 这是我们在Apple向公众发布行动之前所做的事情。

you can use \\n to break the string into multiple lines. 您可以使用\\ n将字符串分成多行。

   NSString *info = [NSString stringWithFormat:@"\n line 1  \n"
                  "line 2 \n"
                  "line 3\n"];

If you want to display the text in a label in multiple lines,you can use 如果要以多行显示标签中的文本,可以使用

    textLabel.numberOfLines = //your number;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM