tt.createFollowButton
收藏我的收藏
基础库 1.19.0 开始支持本方法,这是一个同步方法。
创建关注头条号按钮。
| 前提条件 | 使用该 API 前需先在平台 绑定账号,审核通过才可以使用接口关注账号。 具体路径:【开发者平台】-【基础设置】-【关联设置】- 【头条号绑定】 |
| 业务背景 | 无 |
| 使用限制 | 只支持在今日头条 App 上使用 |
| 注意事项 | 无 |
| 相关教程 | 无 |
语法
tt.createFollowButton(options)
参数说明
options 类型说明
object 类型,属性如下:
| 属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|---|
| type | string | text | 否 | 按钮的类型,取值 image 或 text。image 对应图片按钮,text 对应文本按钮 | 1.19.0 |
| image | string | 否 | 按钮的背景图片,type 为 image 时必填。仅支持本地图片,目录包括代码包目录、临时文件目录和本地用户目录 | 1.19.0 | |
| style | object | 否 | 按钮的样式 | 1.19.0 |
style 类型说明
object 类型,属性如下:
| 属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|---|
| left | number | 20 | 是 | 左上角横坐标 | 1.19.0 |
| top | number | 40 | 是 | 左上角纵坐标 | 1.19.0 |
| width | number | 150 | 是 | 宽度 | 1.19.0 |
| height | number | 40 | 是 | 高度 | 1.19.0 |
| backgroundColor | string | #ffffff | 是 | 背景颜色 | 1.19.0 |
| borderColor | string | #ffffff | 是 | 边框颜色 | 1.19.0 |
| borderWidth | number | 1 | 是 | 边框高度 | 1.19.0 |
| borderRadius | number | 4 | 是 | 边框圆角 | 1.19.0 |
| textAlign | enum | center | 是 | 文本的水平居中方式 | 1.19.0 |
| fontSize | number | 16 | 是 | 字号 | 1.19.0 |
| lineHeight | number | 40 | 是 | 文本的行高 | 1.19.0 |
| textColor | string | #ffffff | 是 | 文本颜色 | 1.19.0 |
textAlign 的合法值
| 值 | 说明 | 最低支持版本 |
|---|---|---|
| left | 居左 | 1.19.0 |
| center | 居中 | 1.19.0 |
| right | 居友 | 1.19.0 |
返回值
| 类型 | 说明 | 最低支持版本 |
|---|---|---|
| object | FollowButton 对象实例 | 1.19.0 |
错误码
代码示例
// 创建关注头条号按钮 const btn = tt.createFollowButton({ type: "image", image: "images/follow_btn.png", style: { left: 20, top: 40, width: 150, height: 40, lineHeight: 40, backgroundColor: "#ff0000", textColor: "#ffffff", textAlign: "center", fontSize: 16, borderRadius: 4, borderWidth: 1, borderColor: "#ff0000", }, });
