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

边栏推荐
- Troubleshooting of high memory usage of redis in a production environment
- [mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
- Codeworks 5 questions per day (1700 average) - day 5
- iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
- 一次生产环境redis内存占用居高不下问题排查
- 15 methods in "understand series after reading" teach you to play with strings
- 一类恒等式的应用(范德蒙德卷积与超几何函数)
- Wireless WiFi learning 8-channel transmitting remote control module
- 16 channel water lamp experiment based on Proteus (assembly language)
- Ncp1342 chip substitute pn8213 65W gallium nitride charger scheme
猜你喜欢
![[calculation of loss in yolov3]](/img/8c/1ad99b8fc1c5490f70dc81e1e5c27e.png)
[calculation of loss in yolov3]

【Win11 多用户同时登录远程桌面配置方法】

Liunx prohibit Ping explain the different usage of traceroute

【SingleShotMultiBoxDetector(SSD,单步多框目标检测)】

Matlab boundarymask function (find the boundary of the divided area)

Wireless WiFi learning 8-channel transmitting remote control module

redis主从模式

什么是数字化存在?数字化转型要先从数字化存在开始

互联网公司实习岗位选择与简易版职业发展规划
自动化测试生命周期
随机推荐
Multi table operation - sub query
redis主从中的Master自动选举之Sentinel哨兵机制
2022年国内云管平台厂商哪家好?为什么?
13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
Sentinel sentinel mechanism of master automatic election in redis master-slave
Codeworks 5 questions per day (1700 average) - day 5
11. (map data section) how to download and use OSM data
Which domestic cloud management platform manufacturer is good in 2022? Why?
codeforces每日5题(均1700)-第五天
13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
byte2String、string2Byte
mmclassification 训练自定义数据
Splunk configuration 163 mailbox alarm
1.php的laravel创建项目
Pytorch weight decay and dropout
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
Reading notes of growth hacker
July Huaqing learning-1
嵌入式软件架构设计-消息交互
Matlab superpixels function (2D super pixel over segmentation of image)