我坚持认为我认为这是一件简单的事情。我有一个自定义表格单元格,其中包含一个UITextView对象。我希望该对象中的文本为灰色。当我在界面生成器中设置颜色时,它显示为灰色,但是在模拟器中,它保持黑色。
以下是其设置方式的摘要:
我更新了MasterViewController来填充我的自定义单元。当我运行模拟器时,就显示数据的自定义单元而言,它们都可以正常工作。
如前所述,当我尝试更改自定义单元格的UITextView中的文本颜色时,就会出现问题。如果在界面构建器中将其设置为浅灰色,则在模拟器中无效。
我在下面包括了相关的代码片段和屏幕截图。我不确定100%是否与问题相关,什么与问题无关,如果您需要查看下面未显示的内容,请询问并提供。
**编辑
当我注销UITextView的color属性时,它输出(空)。请参阅下面的MasterViewController.m代码。
自定义单元格-NTFYNoteCell.h
#import <UIKit/UIKit.h>
@interface NTFYNoteCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UITextView *descriptionText;
@end
取自MasterViewController.m:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NTFYNoteCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NTFYNote *note = _notes[indexPath.row];
cell.titleLabel.text = [note title];
cell.descriptionText.text = [note shortDescription];
NSLog(@"TEXTVIEW: %@", cell.descriptionText);
NSLog(@"TEXT COLOR: %@", cell.descriptionText.textColor); // This outputs (null)
return cell;
}
从上面的代码中调试出来:
2014-01-19 19:42:52.001 appname[5050:70b] TEXTVIEW: <UITextView: 0xa1bfe00; frame = (14 26; 273 57); text = 'This is a generic descrip...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x8be0530>; layer = <CALayer: 0x8be1fe0>; contentOffset: {0, 0}>
2014-01-19 19:42:52.001 appname[5050:70b] TEXT COLOR: (null)
2014-01-19 19:42:52.004 appname[5050:70b] TEXTVIEW: <UITextView: 0xa1cd400; frame = (14 26; 273 57); text = 'This is a generic descrip...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x8b8fb40>; layer = <CALayer: 0x8bf5300>; contentOffset: {0, 0}>
2014-01-19 19:42:52.005 appname[5050:70b] TEXT COLOR: (null)
2014-01-19 19:42:52.007 appname[5050:70b] TEXTVIEW: <UITextView: 0xe17e000; frame = (14 26; 273 57); text = 'This is a generic descrip...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0xd857bb0>; layer = <CALayer: 0xd85d610>; contentOffset: {0, 0}>
2014-01-19 19:42:52.007 appname[5050:70b] TEXT COLOR: (null)
2014-01-19 19:42:52.009 appname[5050:70b] TEXTVIEW: <UITextView: 0x99af200; frame = (14 26; 273 57); text = 'This is a generic descrip...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x8a81ea0>; layer = <CALayer: 0x8a580c0>; contentOffset: {0, 0}>
2014-01-19 19:42:52.009 appname[5050:70b] TEXT COLOR: (null)
UITextView连接到我的“定制单元”中的插座:
在界面生成器中将字体颜色设置为浅灰色:
iPhone模拟器中的外观:
解决了这个问题后,我带着新信息回到Google,发现了以下Stack Overflow问题:
事实证明,如果不选中UITextView属性下的“ Selectable”复选框,它将不响应任何字体更改,包括颜色。
我选中了此框,现在一切正常。
谢谢你的帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句