当前位置:网站首页>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

边栏推荐
- Open3D 欧式聚类
- 2022年国内云管平台厂商哪家好?为什么?
- [pytorch pre training model modification, addition and deletion of specific layers]
- Codeforces Round #804 (Div. 2)
- 调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
- 简单解决redis cluster中从节点读取不了数据(error) MOVED
- pytorch-线性回归
- 谜语1
- 11. (map data section) how to download and use OSM data
- Pytorch weight decay and dropout
猜你喜欢
![[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]](/img/1a/dd7453bc5afc6458334ea08aed7998.png)
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]

redis主从模式

Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)

July Huaqing learning-1

【yolov5.yaml解析】

yolov5目标检测神经网络——损失函数计算原理

13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换

Linux安装部署LAMP(Apache+MySQL+PHP)

【 YOLOv3中Loss部分计算】

【PyTorch预训练模型修改、增删特定层】
随机推荐
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
What is the difference between canvas and SVG?
pytorch-softmax回归
Pytorch linear regression
Hash tag usage in redis cluster
Use and install RkNN toolkit Lite2 on itop-3568 development board NPU
Design of music box based on assembly language
【PyTorch预训练模型修改、增删特定层】
【上采样方式-OpenCV插值】
Matlab boundarymask function (find the boundary of the divided area)
Matlab label2idx function (convert the label matrix into a cell array with linear index)
pytorch-线性回归
[upsampling method opencv interpolation]
JS for循环 循环次数异常
Open3D 网格(曲面)赋色
Yolov5 target detection neural network -- calculation principle of loss function
Programmers are involved and maintain industry competitiveness
[configuration method of win11 multi-user simultaneous login remote desktop]
iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
Dynamic SQL of ibatis