【问题标题】:iPhone - Strike out an NSString [duplicate]iPhone - 删除一个 NSString [重复]
【发布时间】:2011-02-12 02:49:01
【问题描述】:

我想知道是否有一种简单的方法可以在 iPhone 上删除/删除某些文本?

谢谢

【问题讨论】:

  • 用UILabel,或者在-drawRect:中绘制NSString?

标签: iphone objective-c nsstring uifont


【解决方案1】:

是与否,

NSString 是一个简单的类,它只存储未格式化的文本,但您可以使用 NSAttributedString 来存储此类信息,即

NSAttributedString* italicText = [[NSAttributedString alloc] initWithString:myNsString attributes:myCrossOutAttributes];

【讨论】:

  • 注意:NSAttributedString 仅在 ≥3.2 后可用。
  • 拍摄...如果我为3.0开发我不能三振?
  • 不,不使用 NSAttributedString。但是,您可以继承 UILabel 并在 -drawRect: 中添加一些自定义绘图代码,就像 KennyTM 所说的那样。
  • 不幸的是,您是正确的,这给我们留下了“不,这并不容易”作为答案。 ):
  • 有人可以帮我解决难题吗?
【解决方案2】:
NSMutableAttributedString *strikeThroughString = [[NSMutableAttributedString alloc] initWithString:anyString];
[strikeThroughString addAttribute:NSStrikethroughStyleAttributeName value:(NSNumber *)kCFBooleanTrue range:NSMakeRange(0, [as length])];
[m_cObjTaskTitle setAttributedText:strikeThroughString =];
cObjTaskTitle = UILabel ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 2013-08-22
    • 1970-01-01
    • 2011-09-04
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多