【问题标题】:Change color of selectable UITextView更改可选 UITextView 的颜色
【发布时间】:2014-05-18 21:15:16
【问题描述】:

我有一个带有电子邮件地址的UITextView,我想设置它,以便当用户点击它时,它会调出电子邮件控制器。所以我设置了selectabledataDetectorTypes 属性,并输入了所需的电子邮件地址作为UITextView 的文本。

这工作正常,但问题是 IOS7 中文本的自动突出显示与我的 UIViewController 的背景相同的蓝色阴影。所以基本上文字消失了,我需要改变它的颜色。

环顾四周的人建议仅在将文本视图设置为selectable 后更改文本、字体和文本颜色。但这似乎不起作用。无论我尝试将其设置为哪种颜色,它都保持相同的蓝色阴影。

有什么想法吗?这是我正在使用的代码:

UITextView* emailText = [[UITextView alloc] initWithFrame:CGRectMake(20, 230, 280, 40)];
emailText.backgroundColor = [UIColor clearColor];
emailText.editable = NO;
emailText.scrollEnabled = NO;
emailText.dataDetectorTypes = UIDataDetectorTypeAll;
if(IS_OS_7_OR_LATER) {
    emailText.selectable = YES;
}
emailText.font = [UIFont fontWithName:@"OpenSansHebrew-Bold" size:28];
emailText.textColor = [UIColor whiteColor];
emailText.text = @"our email address";
[self.view addSubview:emailText];

【问题讨论】:

    标签: ios uitextview


    【解决方案1】:

    我最终在UITextView 下方放置了一个UIView(请参阅我的问题),这使得我可以直接使用任何我想要的背景颜色。

    如果我可以为UITextView 的文本选择一种颜色会更好,但我想这是一个可以接受的解决方法。

    UIView *emailFrameView = [[UIView alloc] initWithFrame:CGRectMake(20, 230, 280, 50)];
    emailFrameView.backgroundColor = [UIColor greenColor];
    emailFrameView.layer.cornerRadius = 5;
    [self.view addSubview:emailFrameView];
    

    【讨论】:

      猜你喜欢
      • 2019-07-15
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-02
      相关资源
      最近更新 更多