tencent cloud

User Generated Short Video SDK

iOS

ダウンロード
フォーカスモード
フォントサイズ
最終更新日: 2026-05-11 17:46:57

Feature Overview

This document covers sticker and text operation interface classes and methods, including creating, loading, and removing stickers, as well as setting sticker properties (such as time range, animation mode, position, etc.). Usage examples and sticker data model descriptions are also provided.

Related Interface Classes

Interface Class Name
Description
TAVEditor
SDK operation entry class.
ITAVStickerManager
Sticker operation entry class.
TAVMediaStickerItem
Sticker data model class.

Sticker Operation Methods

Get Sticker Operation Interface

Sticker operations are encapsulated in a separate interface, accessible viaTAVEditor to obtain it directly:
// Get TAVEditor API
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"LightCore" ofType:@"bundle"];
self.tavEditor = [[TAVEditor alloc] initWithRenderSize:CGSizeZero assetsPath:bundlePath];
// Get sticker operation interface
id<ITAVStickerManager> stickerManager = [self.tavEditor getStickerManager];

Create Sticker Data Model

All sticker data is stored in the sticker data modelTAVMediaStickerItem, so before operating on stickers, you must first have aTAVMediaStickerItem object,TAVMediaStickerItem
When creating a sticker object, you need to provide the sticker file path and set the display time rangesetTimeRange. If not set, it defaults to the entire asset duration.
// 1. Create a text sticker
NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"text_default" ofType:@"bundle"];
TAVMediaStickerItem *stickerItem = [stickerManager createStickerItem:textPath stickerType:TAVStickerTypeText];
// Set text sticker font
// Get font object. fontPath is the font file path; fontFamily and fontStyle can be empty strings if unknown
PAGFont *pagFont = [PAGFont RegisterFont:fontPath
family:fontFamily
style:fontStyle];
stickerItem.font = pagFont;
stickerItem.timeRange = timerange;

// 2. Create an image sticker
NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"image_default" ofType:@"bundle"];
TAVMediaStickerItem *stickerItem = [stickerManager createStickerItem:stickerPath stickerType:TAVStickerTypeImage];
// Set image
NSString *imagePath = ....;
stickerItem.imageFilePath = imagePath;

// 3. Create an animated sticker
// This is a path pointing to main.pag. The sticker__plfttz_01.bundle directory contains the main.pag file
NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"sticker__plfttz_01" ofType:@"bundle"];
TAVMediaStickerItem *stickerItem = [[TAVMediaStickerItem alloc] initWithStickerID:@"stickerPlfttz01Id" resourceInfoPath:stickerPath];


Load a Sticker

Via Get Sticker Operation Interface to get the sticker operation interfaceTAVStickerManager to load stickers.
[stickerManager loadStickerItem:stickerItem];

Create Custom Sticker Editing View

The SDK provides a default sticker editing view. If the default view does not meet your business needs, you can create a custom sticker editing view.
First, set the data source (conforming to the ITAVStickerViewDataSource protocol) delegate for the sticker view:
@protocol ITAVStickerViewDataSource <NSObject>

/// Return a sticker view for the given sticker object. Can inherit from TAVStickerView to customize controls
/// - Parameter stickerItem: Sticker object
- (TAVStickerView *)stickerViewWithStickerItem:(TAVMediaStickerItem *)stickerItem;
@end
- (void)setStickerViewDataSource:(id<ITAVStickerViewDataSource>)dataSource;


Then, implement the following delegate method in your delegate class to return the created sticker view.
@interface MyStickerContentView : TAVStickerView
/// ...Implement your own business logic
@end


#pragma mark - ITAVStickerViewDataSource
- (TAVStickerView *)stickerViewWithStickerItem:(TAVMediaStickerItem *)stickerItem
{
// Custom sticker view must inherit from TAVStickerView
MyStickerContentView *stickerView = [[MyStickerContentView alloc] initWithStickerItem:stickerItem];
return stickerView;
}

Set Custom Sticker Container Layout

The SDK provides an empty sticker container layout by default. If the default layout does not meet your business needs (e.g., implementing sticker alignment guides), you can create a custom sticker container layout.
First, implement your own sticker container layout:
@interface MyStickerContentView : TAVStickerContentView
/// ...Implement your own business logic
@end
Then, callTAVStickerManager in setStickerContentView to set the custom sticker container layout.
/// Bind the container view for adding stickers
/// - Parameter stickerContentView: Must inherit from TAVStickerContentView
- (void)setStickerContentView:(TAVStickerContentView *)stickerContentView;

Modify Text Sticker Content

To modify the text in a text sticker, simply use the .text property.
// Set text
stickerItem.text = @"";
// Set font
PAGFont *pagFont = [PAGFont RegisterFont:fontPath
family:fontFamily
style:fontStyle];
stickerItem.font = pagFont;
For other properties, see TAVMediaStickerItem.h:
@property (nonatomic, copy) NSString *text; // Text content of the text sticker
@property (nonatomic, strong, readonly) NSString *defaultText; // Default text of the text sticker
@property (nonatomic, strong) UIColor *textColor; // Text color of the text sticker
@property (nonatomic, strong) UIColor *bgColor; // Overall sticker background color
@property (nonatomic, strong) PAGFont *pagFont; // Text font
/// Stroke
@property (nonatomic, assign) BOOL applyTextStroke; // Enable text stroke
@property (nonatomic, assign) CGFloat textStrokeWidth; // Text stroke width
@property (nonatomic, strong) UIColor *textStrokeColor; // Text stroke color

/// Text background
@property (nonatomic, strong) UIColor *textBgColor; // Text background color
@property (nonatomic, assign) CGFloat textBgAlpha; // Text background opacity, range 0 - 1


Modify Custom Image Sticker Image

Image stickers replace images by swapping the placeholder layer.
// 2. Create an image sticker
NSString *stickerPath = [[NSBundle mainBundle] pathForResource:@"image_default" ofType:@"bundle"];
TAVMediaStickerItem *stickerItem = [[TAVMediaStickerItem alloc] initWithStickerID:@"imageDefaultId" resourceInfoPath:stickerPath];
// Switch image
TAVStickerImageItem *imageItem = stickerItem.sticker.imageList.firstObject;
NSString *imagePath = ....;
imageItem.filePath = imagePath;


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック