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

边栏推荐
- Simply solve the problem that the node in the redis cluster cannot read data (error) moved
- 多表操作-子查询
- Time tools
- 【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
- Redis集群的重定向
- 自动化测试生命周期
- Yolov5 target detection neural network -- calculation principle of loss function
- [untitled]
- 【Win11 多用户同时登录远程桌面配置方法】
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
猜你喜欢

互联网公司实习岗位选择与简易版职业发展规划

How to make your products as expensive as possible

redis主从中的Master自动选举之Sentinel哨兵机制

【yolov5.yaml解析】

Four operations and derivative operations of MATLAB polynomials

报错ModuleNotFoundError: No module named ‘cv2.aruco‘

多表操作-自关联查询

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

Error modulenotfounderror: no module named 'cv2 aruco‘

Redis集群(主从)脑裂及解决方案
随机推荐
Principle and performance analysis of lepton lossless compression
Redis cluster (master-slave) brain crack and solution
pytorch-softmax回归
Video networkState 属性
[yolov3 loss function]
Matlab superpixels function (2D super pixel over segmentation of image)
Proof of the thinking of Hanoi Tower problem
16 channel water lamp experiment based on Proteus (assembly language)
【yolov5.yaml解析】
[upsampling method opencv interpolation]
Use and install RkNN toolkit Lite2 on itop-3568 development board NPU
leetcode:1200. Minimum absolute difference
Open3d mesh (surface) coloring
[yolov5.yaml parsing]
iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
Mmclassification training custom data
JS for循环 循环次数异常
2022年国内云管平台厂商哪家好?为什么?
15 methods in "understand series after reading" teach you to play with strings
13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换