Does anyone idea 开发者_StackOverflow社区about how can create UItextivew with Line like so user can easily write text in proper format.
please check this link https://devforums.apple.com/message/217857#217857
is this possible, i have no idea about this.
Thanks you,
Easiest solution is -
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];
}
This will create multiple UIView lines over your text view. The alternative and perhaps easier way (albeit less flexible) to do it is:
// 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
Apologies if the code doesn't compile, as I haven't tested it in Xcode.
Cheers,
Raal
Dapp - the app design app
精彩评论