> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Color Selected Text

> What the CometChat iOS UI Kit v6 offers for coloring selected text: your own button in the composer's formatting toolbar, and why colored text cannot be rendered in message bubbles yet.

> [accordion] AI Integration Quick Reference
>
> ```json theme={null}
> {
>   "products": ["CometChatSwiftUI", "CometChatUIKit"],
>   "toolbar slot": "CometChatMessageComposer trailingToolbarContent: (any ComposerInputController) -> AnyView (SwiftUI) / set(richTextToolbarTrailingView:) (UIKit)",
>   "input handle": "ComposerInputController: text, selection, isCursorCollapsed, insertAtCursor(_:), replaceSelection(_:), toggleFormat(_:), mentionRanges()",
>   "built-in formats": "RichTextFormat: bold, italic, underline, strikethrough, inlineCode, codeBlock, link, bulletList, orderedList, blockquote",
>   "status": "Not supported in iOS v6: there is no color format, and message bubbles do not run custom text formatters, so a color token would show as plain text."
> }
> ```

This guide adds a color button to the composer's formatting toolbar. **The iOS v6 Kit cannot render colored text in a sent message yet**:

* `RichTextFormat` has no color — the formats are bold, italic, underline, strikethrough,
  inline code, code block, link, bulleted list, numbered list and quote.
* Message bubbles draw mentions and markdown from the message itself and do **not** run your
  text formatters, so a `{color:…}` token you put in the text would show as typed.

What iOS v6 does have is the authoring half: your own button at the end of the formatting
toolbar, with a live handle on the input.

## Your own toolbar button

The button receives a `ComposerInputController` while the composer is on screen. Read the text
and the selection, insert or replace text, or toggle one of the built-in formats:

> [tab] SwiftUI
>
> ```swift FormattingComposer.swift theme={null}
> import SwiftUI
> import CometChatSwiftUI
> import CometChatSDK
>
> struct FormattingComposer: View {
>     let user: CometChatSDK.User
>
>     var body: some View {
>         CometChatMessageComposer(
>             user: user,
>             enableRichTextFormatting: true,
>             enabledFormats: Set(RichTextFormat.allCases),
>             trailingToolbarContent: { input in
>                 AnyView(Menu {
>                     Button("Bold + italic") {
>                         input.toggleFormat(.bold)
>                         input.toggleFormat(.italic)
>                     }
>                     Button("Quote") { input.toggleFormat(.blockquote) }
>                 } label: {
>                     Image(systemName: "paintpalette").frame(width: 44, height: 44)
>                 }
>                 .accessibilityLabel("More formats"))
>             }
>         )
>     }
> }
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let composer = CometChatMessageComposer()
> composer.set(user: guideUser)
> composer.set(richTextConfiguration: .allEnabled())
> composer.showRichTextFormattingOptions = true
> composer.set(richTextToolbarTrailingView: { _, _, input in
>     let button = UIButton(type: .system)
>     button.setImage(UIImage(systemName: "paintpalette"), for: .normal)
>     button.accessibilityLabel = "More formats"
>     button.menu = UIMenu(children: [
>         UIAction(title: "Bold + italic") { _ in
>             input.toggleFormat(.bold)
>             input.toggleFormat(.italic)
>         },
>         UIAction(title: "Quote") { _ in input.toggleFormat(.blockquote) },
>     ])
>     button.showsMenuAsPrimaryAction = true
>     return button
> })
> ```
>
> The UIKit view shows only with the single-line toolbar.

> [!WARNING]
>
> The slot lives inside the formatting toolbar: it is not shown while the toolbar is hidden, or
> in a chat with an AI agent. Do not keep the controller after the view goes.

| `ComposerInputController` | Does |
| - | - |
| `text` | the input's plain text, without markdown markers |
| `selection` | the selection as `start...end`, UTF-16 offsets; `start == end` is a caret |
| `isCursorCollapsed` | nothing is selected |
| `insertAtCursor(_:)` | inserts at the caret, replacing any selection |
| `replaceSelection(_:)` | replaces the selection; with a caret, inserts |
| `toggleFormat(_:)` | toggles a built-in format over the selection or at the caret |
| `mentionRanges()` | the ranges mentions occupy, so your change can skip them |

## Next Steps

> [card] [Message Composer](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md)
>
> Rich-text formatting and the toolbar

> [card] [Text Formatter Base Class](https://www.cometchat.com/docs/ui-kit/ios/v6/custom-text-formatter-guide.md)
>
> What formatters can and cannot change

> [card] [Message Template](https://www.cometchat.com/docs/ui-kit/ios/v6/message-template.md)
>
> Replace how a message kind is drawn

> [card] [All Guides](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-overview.md)
>
> Browse the other guides


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.