Swift2.2中的UITextView显示像素化文本,如何恢复丢失的分辨率?

UITextView in Swift2.2 shows Pixelated text, how do I regain the lost resolution?

Image of the pixelated text in the UITextView

有人有什么建议吗?问题的图片在上方的可点击 link 中。

代码:

struct Views {
    static var name_field: UITextView?
}

在viewDidLoad()中

    Views.name_field = UITextView(frame: CGRectMake(0, 0, name_field_width, 50))
    Views.name_field!.textAlignment = NSTextAlignment.Center
    Views.name_field!.font = UIFont.systemFontOfSize(15)
    Views.name_field!.autocorrectionType = UITextAutocorrectionType.No
    Views.name_field!.keyboardType = UIKeyboardType.Default
    Views.name_field!.returnKeyType = .Done
    Views.name_field!.delegate = self

调用这个函数来设置样式

styleIt(Views.name_field!)

添加底部边框样式,然后设置字体等

func styleIt(target: UITextView){
    target.layer.backgroundColor = UIColor.clearColor().CGColor

    let _border = CAShapeLayer()
    _border.backgroundColor = UIColor.whiteColor().CGColor
    _border.frame = CGRectMake(0, CGRectGetHeight(target.frame) - 1.0, CGRectGetWidth(target.frame), 1.0)

    _border.shadowColor = UIColor.whiteColor().CGColor
    _border.shadowOffset = CGSize(width: 3, height: 3)
    _border.shadowOpacity = 0.23
    _border.shadowRadius = 4

    target.layer.addSublayer(_border)

    target.font = UIFont(name: "ClementePDaa-Hairline", size: 24)
    target.textColor = UIColor.whiteColor()
    target.textContainerInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
    applyPlaceholderStyle(target, placeholderText: _SEARCH_TEXT)

    target.returnKeyType = .Done
    target.frame = CGRectIntegral(target.frame)

    target.layer.shouldRasterize = true
    _border.shouldRasterize = true
    target.textInputView.layer.shouldRasterize = true
}

这个 UITextView 是 search_field 的子视图,它只是一个 UIView

search_field!.addSubview(Views.name_field!)

您的文本视图很模糊,因为框架使用了浮点数。 要为您的框架强制使用整数值,只需执行以下操作:

textView.frame = CGRectIntegral(textView.frame)