ios 是否有可能改变的UITableView的字体类型和大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2281768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to change the Font type and size in UITableView?
提问by RAGOpoR
I want to change Font type and size in UITableView
. For example, how would I set it to Tahoma?
我想在UITableView
. 例如,我如何将其设置为 Tahoma?
回答by kennytm
cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:144];
where cell
is a UITableViewCell
you would return in -tableView:cellForRowAtIndexPath:
.
哪里cell
是UITableViewCell
你会回来的-tableView:cellForRowAtIndexPath:
。
Tahoma is not shipped with iOS by default, nor can you legally copy it without a proper license. But you could provide a custom free font if you don't like Arial, see How to include and use new fonts in iPhone SDK?.
默认情况下,iOS 不附带 Tahoma,您也不能在没有适当许可的情况下合法地复制它。但是如果您不喜欢 Arial,您可以提供自定义的免费字体,请参阅如何在 iPhone SDK 中包含和使用新字体?.
回答by rohan-patel
To add to KennyTM'sanswer:
添加到KennyTM 的回答中:
You can use - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
delegate method of UITableView
to configure your UITableViewCell
like this:
你可以使用- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
委托方法UITableView
来配置你UITableViewCell
这样的:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.textColor=[UIColor whiteColor];
cell.detailTextLabel.font=[UIFont fontWithName:@"Helvetica" size:16.0];
cell.detailTextLabel.textColor=[UIColor whiteColor];
}
Apple document reads:
苹果文档如下:
A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.
表格视图在它使用单元格绘制一行之前将此消息发送给它的委托,从而允许委托在显示之前自定义单元格对象。此方法使委托有机会覆盖先前由表视图设置的基于状态的属性,例如选择和背景颜色。委托返回后,表格视图仅设置 alpha 和 frame 属性,然后仅在行滑入或滑出时设置动画。