大佬教程收集整理的这篇文章主要介绍了ios – 设置后,UITextView属性文本为null,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码的样子:
查看控制器:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemATindexPath:(NSIndexPath *)indexPath { TNCommentCollectionViewCell *commentCell = [collectionView dequeueReusableCellWithReusEIDentifier:kCommentCellIdentifier forIndexPath:indexPath]; TNComment *comment = [self.comments objectATindex:indexPath.row]; commentCell.textView.attributedText = [self commentStringForComment:comment]; return commentCell; } - (NSAttributedString *)commentStringForComment:(DAFeedComment *)comment { NSString *usernameString = [NSString StringWithFormat:@"@%@",comment.username]; NSDictionary *usernameAttributes = @{ NSForegroundColorAttributename : [UIColor usernameColor],NSFontAttributename : [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0f] }; NSAttributedString *attributedUsernameString = [[NSAttributedString alloc] initWithString:usernameString attributes:usernameAttributes]; NSMutableAttributedString *labelString = [attributedUsernameString mutableCopy]; NSDictionary *commentAttributes = @{ NSFontAttributename : [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0f] }; [labelString appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]]; [labelString appendAttributedString:[[NSAttributedString alloc] initWithString:comment.comment attributes:commentAttributes]]; return labelString; }
集合视图单元格:
- (void)awakeFromNib { [super awakeFromNib]; self.textView.textContainerInset = UIEdgeInsetsZero; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@SELEctor(textViewTapped:)]; tapGesture.numberOfTapsrequired = 1; [self.textView addGestureRecognizer:tapGesture]; } - (void)textViewTapped:(UITapGestureRecognizer *)recognizer { UITextView *textView = (UITextView *)recognizer.view; NSLayoutManager *layoutManager = textView.layoutManager; CGPoint LOCATIOn = [recognizer LOCATIOnInView:textView]; LOCATIOn.x -= textView.textContainerInset.left; LOCATIOn.y -= textView.textContainerInset.top; NSUInteger characterIndex = [layoutManager characterIndexForPoint:LOCATIOn intextContainer:textView.textContainer fractionOfDistancebetweenInsertionPoints:nil]; if( characterIndex < textView.textStorage.length ) { NSLog(@"%@",textView.attributedText); } }
这导致输出只是“(null)”.但是,如果我打印UITextView的text属性,它将打印实际文本,而不是属性文本.
难道我做错了什么?非常感谢任何帮助
谢谢!
以上是大佬教程为你收集整理的ios – 设置后,UITextView属性文本为null全部内容,希望文章能够帮你解决ios – 设置后,UITextView属性文本为null所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。