Open zyavrik opened 11 years ago
I second this, having line numbers would be hugely helpful.
This might help somebody to add this: http://stackoverflow.com/questions/2836162/how-to-add-line-numbers-to-a-uitextview
I've actually already started trying to implement that along side.
I would love to see it when you get something working. I've been looking for this for a while.
Like that post says, it's working around the line break, or we scroll horizontally. Will be a challenge.
@davemackintosh Yeah I'm messing with it now too.
@davemackintosh Overriding the drawRect
method is significantly reducing performance.
I haven't noticed anything massive yet but stopped playing a few hours ago to get on with some other work that pays me lol. Will have another look later on/tomorrow morning but if you find anything else do let me (us all) know!
Okay so here is what I have so far using that stack overflow post as a guide. It doesn't work perfectly yet but It will eventually. (Note that the code in the image is not mine)
An alternative to overriding -drawRect
might be using NSLayoutManager
.
I think this might actually be easier than I thought, conceptually anyway. Will do an implementation tonight and see if I can come up with anything good.
yes, it is easier than I thought with no measurable performance hit. I'm currently working on a UITableView
that displays the line numbers according to the lines, this gives us line numbers that have the right amount of spacing between them without having to modify the UITextView
or extend it. Will be finishing up on this today and you can review it.
Just so people know, I am still working on this. Work is just a bit hectic at the moment and finding time to finish the implementation is hard! rest assured I will update my fork with line numbers and once it's okayed I'll submit a pull-request.
Some info on my implementation:
After seeing performance issues with using drawRect
method, I've implemented programatically adding a UITableView
to the left of the JLTextView
which contains the line numbers in and the heights of each Cell
is calculated from the font and string size so they're spaced properly.
The issue I'm having at the moment is updating the UITableView
properly while editing and also setting the width of it as you get from single digits to double, to triple, so on and so forth but I'm still working on it! I'll try to get some screen shots when I get a little time to do so!
Okay, now I have some free time I'm back on this :) just as an update. Is anyone else working on this?
@davemackintosh check out https://github.com/illyabusigin/CYRTextView to see a possible implementation of the line numbers... Haven't really dug around, but may be of some use.
Oh. Ha, nice. I'll hit that up instead, having a quick look over it and it's mostly the same as what I've been doing. I'll add this today and remove what I've done.
Required support for line numbers.