前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS18适配指南之UITextView

iOS18适配指南之UITextView

原创
作者头像
YungFan
发布2024-09-09 11:27:55
1480
发布2024-09-09 11:27:55
举报
文章被收录于专栏:学海无涯

介绍

  • 支持自定义富文本格式编辑。
  • 选中文本后,在弹出的气泡菜单中选择 Format -> More...,可以查看自定义格式,然后进行字体、颜色、对齐、列表等设置。

使用

  • 代码。
代码语言:swift
复制
import UIKit

class ViewController: UIViewController {
    lazy var textView: UITextView = {
        let textView = UITextView(frame: CGRect(x: 0, y: 0, width: 300, height: 500))
        textView.center = view.center
        textView.text = "WWDC24 上 Apple 发布了 iOS 18,推出了很多新的内容。在掌握了基于 iOS 17 开发的基础上,只要学习以下的新特性就能轻松过渡到 iOS 18。"
        textView.font = .systemFont(ofSize: 21)
        textView.borderStyle = .none
        // 开启富文本编辑
        textView.allowsEditingTextAttributes = true
        // iOS18新增,自定义Format选项
        textView.textFormattingConfiguration = .init(groups: [
            // 第1组
            .group([
                .component(.formattingStyles, .automatic),
                .component(.fontAttributes, .small),
                .component(.fontPicker, .regular),
                .component(.fontSize, .small),
                .component(.fontPointSize, .mini)
            ]),
            // 第2组
            .group([
                .component(.textAlignment, .mini),
                .component(.textAlignmentAndJustification, .mini),
                .component(.textIndentation, .mini),
                .component(.lineHeight, .mini),
                .component(.listStyles, .regular)

            ]),
            // 第3组
            .group([
                .component(.textColor, .extraLarge),
                .component(.highlight, .mini),
                .component(.highlightPicker, .large)
            ])
        ])
        return textView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(textView)
    }
}
  • 效果。
UITextView.gif
UITextView.gif

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 介绍
  • 使用
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档