当前位置:网站首页>Swift - enables textview to be highly adaptive
Swift - enables textview to be highly adaptive
2022-07-05 12:08:00 【RRJia】
Realize the idea :
Use UITextViewDelegate In the agency “textViewDidChange() Method ” Realization .
Implementation method :
Step one : establish TextViewAdapt.swift file , Add to TextView Control , And set up textView.delegate = self( Be sure to set up the proxy , Otherwise it doesn't work !!).
import UIKit
class TextViewAdapt: UIViewController {
private var label = UILabel()
private var textView = UITextView()
override func viewDidLoad() {
// add to label Control
self.label.frame = CGRect(x: 50, y: 150, width: 60, height: 30)
self.label.backgroundColor = .yellow
// Set the prompt text to “ Please enter ”
self.label.text = " Please enter "
self.view.addSubview(self.label)
// add to textView Control
self.textView.frame = CGRect(x: 130, y: 150, width: 200, height: 30)
// Set up textView The border width of
self.textView.layer.borderWidth = CGFloat(1)
// Set up textView The border color of
self.textView.layer.borderColor = UIColor.black.cgColor
self.view.addSubview(self.textView)
// ( important !! Must do !!) Set up textView Agent for , And implement the corresponding methods in the extension class !!!
self.textView.delegate = self
}
}Step two : Because step 1 is set textView.delegate = self, So here we are TextViewAdapt In the extension class of Implementing agent methods .
// Realization TextView agent
extension TextViewAdapt: UITextViewDelegate {
// textView Every time it changes , Will call this method
func textViewDidChange(_ textView: UITextView) {
// Preset textView Size , Set the width to a fixed width , The height is set to CGFloat The maximum of
let presetSize = CGSize(width: textView.frame.size.width, height: CGFloat.greatestFiniteMagnitude)
// Recalculate textView Size
let newSize = textView.sizeThatFits(presetSize)
// to update textView Size
self.textView.frame = CGRect(origin: CGPoint(x: textView.frame.origin.x, y: textView.frame.origin.y), size: CGSize(width: textView.frame.size.width, height: newSize.height))
}
}result :TextView Highly adaptive success

边栏推荐
- Hiengine: comparable to the local cloud native memory database engine
- 【L1、L2、smooth L1三类损失函数】
- 【无标题】
- Solve readobjectstart: expect {or N, but found n, error found in 1 byte of
- 报错ModuleNotFoundError: No module named ‘cv2.aruco‘
- 投资理财适合女生吗?女生可以买哪些理财产品?
- 嵌入式软件架构设计-消息交互
- 【PyTorch预训练模型修改、增删特定层】
- redis 集群模式原理
- Shell script file traversal STR to array string splicing
猜你喜欢
![[yolov3 loss function]](/img/79/87bcc408758403cf3993acc015381a.png)
[yolov3 loss function]

Thoughts and suggestions on the construction of intelligent management and control system platform for safe production in petrochemical enterprises

Codeworks 5 questions per day (1700 average) - day 5

13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
![[deploy pytoch project through onnx using tensorrt]](/img/b6/ec95f028f749753666c7877134ad70.png)
[deploy pytoch project through onnx using tensorrt]

Matlab imoverlay function (burn binary mask into two-dimensional image)

Principle of redis cluster mode

Reading notes of growth hacker

Redis集群(主从)脑裂及解决方案

Multi table operation - sub query
随机推荐
vscode快捷键
redis的持久化机制原理
Sentinel sentinel mechanism of master automatic election in redis master-slave
Multi table operation - sub query
【上采样方式-OpenCV插值】
How to clear floating?
mmclassification 训练自定义数据
Codeworks 5 questions per day (1700 average) - day 5
How to make your products as expensive as possible
Check the debug port information in rancher and do idea remote JVM debug
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
查看多台机器所有进程
《看完就懂系列》15个方法教你玩转字符串
iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
[upsampling method opencv interpolation]
Open3D 网格(曲面)赋色
1. Laravel creation project of PHP
redis主从模式
【yolov5.yaml解析】
[deploy pytoch project through onnx using tensorrt]