Swift2.2中的UITextView显示了像素化文本,如何重新获得丢失的分辨率?

时间:2016-06-13 21:20:07

标签: xcode swift uitextview ios9 resolution

App screen

有没有人有任何建议?问题的图像位于上面的可点击链接中。

代码:

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!)

1 个答案:

答案 0 :(得分:0)

您的文字视图模糊,因为框架使用的是浮动数字。 要强制框架的整数值,请执行以下操作:

textView.frame = CGRectIntegral(textView.frame)