Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draggable textview position problem #88

Open
HardikDG opened this issue Nov 6, 2017 · 2 comments
Open

Draggable textview position problem #88

HardikDG opened this issue Nov 6, 2017 · 2 comments

Comments

@HardikDG
Copy link

HardikDG commented Nov 6, 2017

I am using 'ACEDrawingDraggableTextTool' in the project. I am running the code in the Xcode 9. iPhone X/iPhone 8 plus simulator.

The issue is, the text view is not getting placed at the cursor location. When I click on the screen it is placed some points down the cursor pointer.
I want to create text view from the touch point itself instead of another location. How can I achieve it?

Other controls are working properly as per the touch location.

@acerbetti
Copy link
Owner

Thanks, I'll take a look

@pineappleslikei
Copy link

Not sure if anyone cares 6 and a half years later, but looks like origin changing on 587

- (void)adjustsWidthToFillItsContents
{
NSString *text = (![self.text isEqualToString:@""] || !self.placeholder) ? self.text : self.placeholder;
UIFont *font = [UIFont fontWithName:self.font.fontName size:self.font.pointSize];
// Hotfix: despite exact text measurement, label text ends up clipped either on the beginning or the end.
// Inserting a couple extra characters here makes the end stick out awkwardly sometimes, but avoids the
// issue if you rotate the text.
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:[text stringByAppendingString:@"xx"]
attributes:@{ NSFontAttributeName : font }];
CGRect rectSize = [attributedText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGRectGetHeight(self.frame)-24)
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
float w1 = (ceilf(rectSize.size.width) + 24 < 50) ? self.frame.size.width : ceilf(rectSize.size.width) + 24;
float h1 =(ceilf(rectSize.size.height) + 24 < 50) ? 50 : ceilf(rectSize.size.height) + 24;
CGRect viewFrame = self.superview.bounds;
viewFrame.size.width = w1 + 24;
viewFrame.size.height = h1;
self.superview.bounds = viewFrame;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants