English 中文(简体)
UITextView 设置文本颜色在 UITableViewCell 中更改布局
原标题:UITextView setTextColor changes layout in UITableViewCell

I am trying to use the solution on the following page: UITextView highlightedTextColor or similar option?

然而,我发现当我在UITextView上调用 SetTextColor 并设置颜色到除彩色黑色以外的任何颜色时, UITextView 中的内容似乎有所改变,而我设置的颜色却不取而代之。

我可以通过修改我的UITableViewCell的以下初始化代码来重复这种行为:

_notesTextView = [[UITextView alloc] initWithFrame:CGRectZero];
[_notesTextView setFont:[UIFont systemFontOfSize:12.0]];
[_notesTextView setTextColor:[UIColor redColor]];
[_notesTextView setUserInteractionEnabled:NO];
[self.contentView addSubview:_notesTextView];

上面的代码将使文本View 显示我期望的偏移, 与我将默认颜色或设置为黑色颜色时相比, 文本也不会显示为红色 。

这太奇怪了 - 知道会有什么问题吗?

问题回答

不使用 CGRectZero 启动框架时使用 CGRectZero, 因为它启动框架的某个值, 您可能根据具体情况知道, 所以如果您创建了自定义的 UIT 可查看器, 那么只需在输入时设置框架, 或者

-(void)layoutSubViews
{

}

我确认文本Color确实改变了文本的位置(我上下调调)。我也尝试了InitWithFrame(50, 20, 250, 31), 并且仍然遇到同样的问题。

我所发现的解决这个问题的方法是使用属性文本对齐并将其设定为一个值:UITextAllignmentCenter、UITExextAllignmentLeft、UITExplignmentRight。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签