【发布时间】:2014-03-19 03:50:05
【问题描述】:
我在它自己的类中有一个 UITextView,我正在尝试获得最大数量的工作行,以便文本不会超出 UITextView 的范围,以及字符换行工作,因为它希望始终处于自动换行模式。但是,行高 (4.9) 可以正常工作。
我不确定是什么导致了此故障。如有任何帮助,我将不胜感激。
这是我正在使用的代码:
CustomTextView.h
#import <UIKit/UIKit.h>
@interface CustomTextView : UITextView <NSLayoutManagerDelegate>
@end
CustomTextView.m
#import "CustomTextView.h"
@implementation CustomTextView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
self.font = [UIFont systemFontOfSize:21.0];
self.dataDetectorTypes = UIDataDetectorTypeAll;
self.layoutManager.delegate = self;
self.tintColor = [UIColor companyBlue];
[self setLinkTextAttributes:@{NSForegroundColorAttributeName:[UIColor companyBlue]}];
self.contentInset = UIEdgeInsetsMake(0.5, 0, 0, 0);
self.scrollEnabled = NO;
self.textContainer.maximumNumberOfLines = 9;
self.textContainer.lineBreakMode = NSLineBreakByCharWrapping;
}
return self;
}
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
{
return 4.9;
}
@end
【问题讨论】:
-
你试过
self.numberOfLines = 9。我在maximumNumberOfLines上找不到任何东西。 -
maximumNumberOfLines 是 UITextView 的 textContainer 属性的一个属性
-
那没有回答问题。你试过
self.numberOfLines = 9吗? -
UITextView 上没有 numberOfLines 属性
-
哦,垃圾... UILabel 有
numberOfLines,而不是UITextView。
标签: ios objective-c ios7 uitextview