如何在没有Storyboard的UITableViewRowAction中进行自定义字体和颜色 [英] How to do custom font and color in UITableViewRowAction without Storyboard

查看:197
本文介绍了如何在没有Storyboard的UITableViewRowAction中进行自定义字体和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有经典的TableView,如果你滑动而不是单击按钮,你可以删除项目。我知道如何在单元格上设置自定义背景,但我找不到如何设置自定义字体和颜色。

I have classic TableView where you can delete item if you swipe and than clicking on the button. I know how to set custom background on the cell, but I can't find how I can set custom font and color for that.

感谢您的帮助!

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?  {

    var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, 
                   title: "Delete", 
                   handler: { 
                      (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
                           println("Delete button clicked!")
                   })

    deleteAction.backgroundColor = UIColor.redColor()

    return [deleteAction]
}


推荐答案

如何使用自定义字体?



这很简单。

How to use a custom font?

It's pretty easy.


  1. 首先,您需要将自定义字体文件包含在项目中。

  2. 接下来,转到到您的info.plist文件并添加一个新条目,其中包含由应用程序提供的字体键。请注意,此条目应为数组。

  3. 然后将这些文件的名称添加为此数组的元素。

  1. Firstly, you need to include your custom font files to your project.
  2. Next, go to your info.plist file and add a new entry with the key "Fonts provided by application". Note that this entry should be an Array.
  3. Then add the names of these files as elements of this array.

就是这样!你需要的只是按照这个名字使用字体

And that's it! All you need then is to use the font by its name like this

cell.textLabel.font = [UIFont fontWithName:@FontNamesize :16];

更简单。您所需要的只是

Even easier. All you need is

cell.textlabel.textcolor = UIColor.redColor()

在您的情况下,您想要更改RowAction的字体。所以我想到的只有两个解决方案。一个使用 [UIColor colorWithPatterImage:]

In your case you want to change the font of the RowAction. So I think of only 2 solutions. One to use [UIColor colorWithPatterImage:]

或者您可以使用 [[UIButton外观] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; 因为RowAction包含一个按钮。

Or you can user [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; because the RowAction contains a button.

这篇关于如何在没有Storyboard的UITableViewRowAction中进行自定义字体和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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