You need to enable JavaScript to run this app. 如何修改Ant Design Image组件预览功能操作栏的图标?
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Ant Design Image组件预览功能操作栏的图标?

Ant Design Image 组件预览自定义图标解决方案

preview.icons 属性为对象类型,而非你代码中写的数组类型,对象的键对应预览工具栏的各个操作按钮,值传入自定义图标组件即可。

支持自定义的按钮映射键

  • rotateLeft:向左旋转操作按钮
  • rotateRight:向右旋转操作按钮
  • zoomIn:放大操作按钮
  • zoomOut:缩小操作按钮
  • fullscreen:全屏查看操作按钮
  • close:关闭预览操作按钮

完整代码示例

// 先导入你需要用到的图标,也可以替换为自己封装的自定义图标组件
import { RotateLeftOutlined, RotateRightOutlined, ZoomInOutlined, ZoomOutOutlined, FullscreenOutlined, CloseOutlined } from '@ant-design/icons';
import { Image } from 'antd';

// 组件内使用
<Image
  src={imageUrl}
  preview={{
    visible: state.visible,
    onVisibleChange: (visible) => closeModal(),
    destroyOnClose: true,
    icons: {
      rotateLeft: <RotateLeftOutlined />,
      rotateRight: <RotateRightOutlined />,
      zoomIn: <ZoomInOutlined />,
      zoomOut: <ZoomOutOutlined />,
      fullscreen: <FullscreenOutlined />,
      close: <CloseOutlined />
      // 不需要的按钮直接给对应键赋值为null即可隐藏
    }
  }}
/>

内容的提问来源于stack exchange,提问作者Rohan Keskar18

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 23:24:01