私はいくつかの単語から多くの単語の範囲のテキストを含むUITextViewを持っています。 アプリを使用している間、テキストビューの高さは固定されており、スクロールが有効になっているため、ユーザーは長いテキストを表示できます。iOS 9 - UITextViewはスクロールせずにテキストビューを満たすためにフォントサイズを縮小しますか?
ただし、ユーザーはネイティブ共有機能を使用して画面を「共有」することができます。このプロセスでは、画像に使用する画面のスクリーンショットと、追加されたいくつかの追加のUI要素を取ります。スクリーンショットをスクロールできないので、UITextViewのスクロール機能を無効にし、長いテキストのフォントを縮小しようとしましたが、UITextViewができるだけいっぱいになるように小さなテキストのフォントを増やしました。
のiOSの古いバージョンを上で動作するようにこのように使用するが、iOSの9は、いくつかの問題を持っているようだし、今では、テキストの一部の遮断:
片側ノートを、このビューはXIBファイルに組み込まれており、 autolayoutを使用します。
override func awakeFromNib() {
super.awakeFromNib()
self.translatesAutoresizingMaskIntoConstraints = false
if UIDevice.iPad() || UIDevice.iPadPro() {
bobbleheadViewWidthConstraint.constant = 300.0
bobbleheadViewHeightConstraint.constant = 600.0
self.updateConstraintsIfNeeded()
self.layoutIfNeeded()
}
speechBubbleView.roundCornersWithRadius(5.0)
}
class func shareViewForQuote(quote: Quote) -> BTVShareView? {
if let shareView = UINib(nibName: "BTVShareView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as? BTVShareView {
shareView.bobbleheadView.image = UIImage(named: quote.character!.name!.stringByReplacingOccurrencesOfString(" ", withString: "-"))
shareView.textView.text = quote.text
shareView.textView.font = UIFont.systemFontOfSize(60.0)
// Re-size quote text
shareView.updateTextFont()
return shareView
}
return nil
}
func updateTextFont() {
let minFontSize: CGFloat = 1.0
var currentFontSize: CGFloat = 100.0
while (currentFontSize > minFontSize && textView.sizeThatFits(CGSizeMake(textView.frame.size.width, textView.frame.size.height)).height >= textView.frame.size.height) {
currentFontSize -= 1.0
textView.font = textView.font!.fontWithSize(currentFontSize)
}
}