如何在NSString中捕获特殊指示的**字符**并加粗它们之间的内容?
我无法在指定的一对“**”字符之间加粗任何字符。 例如,在此NSString中:
"The Fox has ran **around** the corner."
应该读到:“狐狸走到了拐角处”
这是我的代码:
NSString *questionString = queryString; NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:questionString]; NSRange range = [questionString rangeOfString:@"\\*([^**]+)\\*" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch]; if (range.location != NSNotFound) { [mutableAttributedString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:AGHeavyFontName size:size]} range:range]; } [[mutableAttributedString mutableString] replaceOccurrencesOfString:@"*" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, queryString.length)]; return mutableAttributedString;
我有问题 – 这段代码仍然会用一对“*”来捕捉字符,所以在这种情况下,
"The fox has ran *around the corner*
仍然会读作“狐狸已经跑到拐角处”,当它不应该时。
有任何想法吗?
- 当单元格仍然显示时,UICollectionView中的大单元格被移除
- 关于设置的一点
- 我如何定制我的UICollectionViewCell子类的select状态?
- 学习Swift和iOS开发第5部分:数组
- 首次出现时不能更改UITableViewCell中的UILabel的框架(使用Autolayout)
- IOS:一个帐号两个iOS开发者程序
- 在放大时使用MKMapView在setUserTrackingMode上崩溃
- 通过NSRegularExpression获取Javascript函数之间的具体值?
- WatchOS2 WCSession WCSession可以在WatchKitExtension中拥有多少个代理?