Skip to content

Commit

Permalink
Merge pull request #57 from iostang/master
Browse files Browse the repository at this point in the history
自定义无序符号&对齐方式
  • Loading branch information
rztime authored Sep 18, 2024
2 parents 1eeeff3 + baeab64 commit a155a70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Example/RZRichTextView/HowToUseDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public extension RZRichTextViewModel {

let viewModel = RZRichTextViewModel.init()
viewModel.canEdit = edit
viewModel.ulSymbol = ""
//viewModel.ulSymbol = "*"
viewModel.ulSymbolAlignment = .center
viewModel.ulSymbolFont = .systemFont(ofSize: 14, weight: .medium)

/// 链接颜色
viewModel.defaultLinkTypingAttributes = [.foregroundColor: UIColor.qhex(0x307bf6), .underlineColor: UIColor.qhex(0x307bf6), .underlineStyle: NSUnderlineStyle.styleSingle.rawValue]
/// 显示音频文件名字
Expand Down
5 changes: 3 additions & 2 deletions RZRichTextView/Classes/RZRichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public extension RZRichTextView {
index = 1
}
lastType = .ul
temp.append(("·", range, p, dict))
temp.append((viewModel.ulSymbol, range, p, dict))
} else {
lastType = .none
index = 0
Expand All @@ -645,9 +645,10 @@ public extension RZRichTextView {
if index != "" {
let rect = self.qcaretRect(for: range.location)
let view = RZTextListView.init().qframe(.init(x: 3, y: rect.origin.y, width: 30, height: rect.size.height))
.qfont((dict[.font] as? UIFont) ?? .systemFont(ofSize: 16))
.qfont(viewModel.ulSymbolFont ?? (dict[.font] as? UIFont) ?? .systemFont(ofSize: 16))
.qtextColor((dict[.foregroundColor] as? UIColor) ?? .black)
.qtext("\(index)")
.qtextAliginment(viewModel.ulSymbolAlignment)
self.addSubview(view)
}
}
Expand Down
4 changes: 4 additions & 0 deletions RZRichTextView/Classes/RZRichTextViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ open class RZRichTextViewModel: NSObject {
/// 初始化的时候配置此项,在编辑过程中,如果想禁用编辑,直接设置textView.isEditable = false
open var canEdit: Bool = true

open var ulSymbol:String = "·"
open var ulSymbolAlignment:NSTextAlignment = .right
open var ulSymbolFont:UIFont?

public override init() {
super.init()
/// 默认居左
Expand Down

0 comments on commit a155a70

Please sign in to comment.