用Line构建UITextview

时间:2010-05-11 07:42:16

标签: iphone

有没有人想过如何使用Line创建UItextivew,这样用户可以轻松地以适当的格式编写文本。

请检查此链接 https://devforums.apple.com/message/217857#217857

这是可能的,我对此一无所知。

谢谢你,

1 个答案:

答案 0 :(得分:0)

最简单的解决方案是 -

NSInteger distanceBetweenLines = 50;  // Distance between each line
NSInteger startMargin = 20;      // For any starting margin for our first line
for (int i = 0; i < numberOfLines; i++) {
  UIView *lineView = [[UIView alloc] init];
  [lineView setFrame:CGRectMake(0, distanceBetweenLines * i + startMargin,
                                200, 1)];
  [lineView setBackgroundColor:[UIColor blackColor]];
  [self addSubview:lineView];
  [lineView release];
}

这将在文本视图上创建多个UIView行。另一种也许更简单的方法(虽然不那么灵活)是:

// linesImage is an image with a white background and black lines

UIImageView *linesImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"linesImage"]];
[linesImageView setFrame:CGRectMake(x, y, width, height)];
[self addSubview:linesImageView];
[linesImageView release];
// Just need to maker sure the textview is added to the view after imageview is created to make sure it is on top... or just bring the textview forward in your subviews stack
textview.backgroundColor = [UIColor clearColor];  // So that lines image can be seen through the text view

如果代码没有编译,请道歉,因为我还没有在Xcode中测试它。

干杯,

Raal

Dapp - the app design app