文字上添加删除线

NSString * str = @"ABCDEFG HIJKLMN";

UILabel * aLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 300)];

aLab.text = str;

NSMutableAttributedString * testAttriString = [[NSMutableAttributedString alloc] initWithString:str];

[testAttriString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, testAttriString.length)];

aLab.attributedText = testAttriString;

[self.view addSubview:aLab];

[原文链接](http://wpdome.sinaapp.com/?p=177%20%E5%8E%9F%E6%96%87%E9%93%BE%E6%8E%A5)[http://wpdome.sinaapp.com/?p=177](http://wpdome.sinaapp.com/?p=177)
### 实现 Ant Design 文本删除线 在 Ant Design 中可以通过内联样式或 CSS 类来为文本添加删除线效果。对于简单的场景,可以直接应用 `style` 属性并设置 `textDecoration` 为 `'line-through'` 来快速实现这一功能[^1]。 ```jsx import React from 'react'; import { Typography } from 'antd'; const App = () => ( <Typography> <p style={{ textDecoration: 'line-through', verticalAlign: 'text-bottom' }}>这段文字带有删除线</p> {/* 使用 inline-style */} </Typography> ); ``` 为了保持代码整洁以及便于维护,在实际开发过程中更推荐定义专门的 CSS 或者使用 Ant Design 提供的内置类名 `.ant-typography-delete` 来处理此类需求[^3]: ```jsx import React from 'react'; import { Typography, Button } from 'antd'; import './custom.css'; // 假设自定义样式文件路径如此 // 自定义样式文件 custom.css 内容如下: /* .custom-deleted { text-decoration: line-through; } */ const App = () => ( <> <Typography.Paragraph className="custom-deleted">这是通过外部CSS类添加删除线文字。</Typography.Paragraph> {/* 或者利用 antd 的内置类 */} <Typography.Delete>这是使用 Ant Design 内置类的文字。</Typography.Delete> {/* 结合按钮操作动态切换删除线状态的例子 */} const [isDeleted, setIsDeleted] = React.useState(false); <Button onClick={() => setIsDeleted(!isDeleted)}>Toggle Delete Line</Button> <Typography.Paragraph className={isDeleted ? "custom-deleted" : ""}> 动态控制是否显示删除线。 </Typography.Paragraph> </> ); ``` 上述方法不仅适用于静态展示,也支持基于交互逻辑动态改变文本样式的场景。当涉及到复杂的应用程序设计时,遵循一致性的原则有助于降低用户的认知负担[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值