UITableViewCell drawInRect iOS7

编程入门 行业动态 更新时间:2024-10-28 15:27:27
本文介绍了UITableViewCell drawInRect iOS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我正在尝试使用以下代码在iOS 7中的UITableViewCell中绘制字符串

Hi I am trying to draw strings in my UITableViewCell in iOS 7 with the following code

-(void)drawRect:(CGRect)rect{ [super drawRect:rect]; CGRect playerNameRect = CGRectMake(0, kCellY, kPlayerNameSpace, kCellHeight); NSDictionary*dictonary = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor hmDarkGreyColor], NSForegroundColorAttributeName, kFont, NSFontAttributeName, nil]; [self.playerName drawInRect:playerNameRect withAttributes:dictonary]; }

但是我无法得到任何东西......自我.playerName不是nil,并且playerNameRect是正确的。

However I can not get anything to appear... self.playerName is not nil, and the playerNameRect is correct.

我以前使用以下代码执行相同的操作但最近在iOS 7中已弃用

I was previously using the following code to do the same thing but was recently deprecated in iOS 7

[self.playerName drawInRect:playerNameRect withFont:kFont lineBreakMode:NSLineBreakByTruncatingTail alignment:NSTextAlignmentCenter];

同样奇怪的是我无法在UITableViewCell上绘制drawRect ...当我在一个UIView上使用drawRect时,不推荐使用的代码可以工作。

What is also strange is I can not get anything to draw in drawRect on a UITableViewCell... The deprecated code works when I am drawingRect on just a UIView.

推荐答案

你不应该使用 UITableViewCell 's drawRect 执行自定义绘图的方法。正确的方法是创建一个自定义 UIView 并将其添加为您的单元格的子视图(作为 contentView的子视图 property)。您可以将绘图代码添加到此自定义视图中,一切正常。

You shouldn't use UITableViewCell's drawRect method to perform custom drawing. The proper way to do it is to create a custom UIView and add it as a subview of your cell (as a subview of the contentView property). You can add the drawing code to this custom view and everything will work fine.

希望这会有所帮助!

查看这些帖子:

表视图单元格自定义图纸1

表视图单元格自定义绘图2

表格查看单元格自定义图纸3

更多推荐

UITableViewCell drawInRect iOS7

本文发布于:2023-10-08 03:29:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UITableViewCell   drawInRect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!