阅读(2572) 赞(2)

tt.createFollowButton

2020-02-15 02:04:04 更新
基础库 1.19.0 开始支持本方法,低版本需做兼容处理。
暂时只支持在今日头条 App 上使用(使用说明)。

创建关注头条号按钮。


参数

Object 类型,属性如下:

属性类型默认值必填描述
typestring是按钮的类型,取值 image 或 text。image 对应图片按钮,text 对应文本按钮
imagestring否按钮的背景图片,type 为 image 时必填。仅支持本地图片,目录包括代码包目录、临时文件目录和本地用户目录
styleobject是按钮的样式

style 对象说明

属性类型默认值必填说明
leftnumber是左上角横坐标
topnumber是左上角纵坐标
widthnumber是宽度
heightnumber是高度
backgroundColorstring是背景颜色
borderColorstring是边框颜色
borderWidthnumber是边框宽度
borderRadiusnumber是边框圆角
textAlignstring是文本的水平居中方式
fontSizenumber是字号
lineHeightnumber是文本的行高
textColorstring是文本颜色

style.textAlign 属性合法值

值说明
left居左
center居中
right居右


返回

返回一个 FollowButton 对象


示例

// 创建关注头条号按钮
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"
  }
});