-
Notifications
You must be signed in to change notification settings - Fork 12
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
Text On Layer #3
Comments
Is like this?
Marcelo Perretta <[email protected]>于2017年10月4日 周三上午12:16写道:
… hi... me again 😄
I want to ask you about how can I add text inside the lines with the
distance between the start poing and the end point?
Can you help me?
Thanks
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/APEgNLZveEYHUnjnNSTuMkOkroEL5Kssks5sol31gaJpZM4PsYyC>
.
|
sorry I am finding job so a little busy
I send you a video but it seems fail so I change it with picture
The following code may be useful for u :
**********************************************************************************************************************
- (void)drawWord:(NSString *)rulerLength{
NSDictionary *attribute = @{NSFontAttributeName: [UIFont
systemFontOfSize:14]};
CGRect rect = [rulerLength boundingRectWithSize:CGSizeMake(MAXFLOAT,
MAXFLOAT)
options:
NSStringDrawingUsesLineFragmentOrigin
attributes:attribute
context:nil];
//ensure the word drawing of start point
CGFloat wordOffsetAngle = [self angleMiddleWithFirstPoint:self.
firstPoint andSecondPoint:self.lastPoint];
CGPoint pointMiddle = [self middlePoint:self.firstPoint and:self.
lastPoint];
CGFloat angle = [self angleWordWithFirstPoint:self.firstPoint
andSecondPoint:self.lastPoint];
CGPoint wordPoint;
CGFloat dx = self.lastPoint.x - self.firstPoint.x;
if (dx > 0) {
pointMiddle = CGPointMake(pointMiddle.x+5*sin(angle), pointMiddle.y+
5*cos(angle));
wordPoint =
CGPointMake(pointMiddle.x-(rect.size.width/2)*cos(wordOffsetAngle),
pointMiddle.y-(rect.size.width/2)*sin(wordOffsetAngle));
} else {
pointMiddle = CGPointMake(pointMiddle.x-5*sin(angle), pointMiddle.y-
5*cos(angle));
wordPoint =
CGPointMake(pointMiddle.x+(rect.size.width/2)*cos(wordOffsetAngle),
pointMiddle.y+(rect.size.width/2)*sin(wordOffsetAngle));
}
CGFloat wordAngle = [self angleWordDirectionWithFirstPoint:self.
firstPoint andSecondPoint:self.lastPoint];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSelectFont(context, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
if (self.color) {
CGContextSetFillColorWithColor(context, self.color.CGColor);
}
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetTextMatrix(context, CGAffineTransformRotate(
CGAffineTransformMake(1, 0, 0, -1, 0, 0), wordAngle));
CGContextShowTextAtPoint(context, wordPoint.x, wordPoint.y,
[rulerLength UTF8String], rulerLength.length);
}
- (CGFloat)angleMiddleWithFirstPoint:(CGPoint)firstPoint andSecondPoint:(CGPoint)secondPoint
{
CGFloat dx = secondPoint.x - firstPoint.x;
CGFloat dy = secondPoint.y - firstPoint.y;
CGFloat angle = atan2f(fabs(dy), fabs(dx));
NSLog(@"angle:%lf",angle);
if (dx >= 0 && dy >= 0) {
return angle;
}
if (dx <= 0 && dy >= 0) {
return M_PI-angle;
}
if (dx <= 0 && dy <= 0) {
return angle-M_PI;
}
if (dx >= 0 && dy <= 0) {
return -angle;
}
return angle;
}
-(CGPoint)middlePoint:(CGPoint)start and:(CGPoint)end{
return CGPointMake((start.x+end.x)/2, (start.y+end.y)/2);
}
- (CGFloat)angleWordWithFirstPoint:(CGPoint)firstPoint andSecondPoint:(CGPoint)secondPoint
{
CGFloat dx = secondPoint.x - firstPoint.x;
CGFloat dy = secondPoint.y - firstPoint.y;
CGFloat angle = atan2f(fabs(dy), fabs(dx));
NSLog(@"angle:%lf",angle);
if (dx >= 0 && dy >= 0) {
return -angle;
}
if (dx <= 0 && dy >= 0) {
return M_PI+angle;
}
if (dx <= 0 && dy <= 0) {
return M_PI-angle;
}
if (dx >= 0 && dy <= 0) {
return angle;
}
return angle;
}
- (CGFloat)angleWordDirectionWithFirstPoint:(CGPoint)firstPoint andSecondPoint:(CGPoint)secondPoint
{
CGFloat dx = secondPoint.x - firstPoint.x;
CGFloat dy = secondPoint.y - firstPoint.y;
CGFloat angle = atan2f(dy, dx);
if (dx > 0) {
angle = -angle;
} else {
angle = M_PI-angle;
}
return angle;
}
2017-10-13 18:58 GMT+08:00 Jarvi Liu <[email protected]>:
… Is like this?
Marcelo Perretta ***@***.***>于2017年10月4日 周三上午12:16写道:
> hi... me again 😄
>
> I want to ask you about how can I add text inside the lines with the
> distance between the start poing and the end point?
>
> Can you help me?
>
> Thanks
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#3>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/APEgNLZveEYHUnjnNSTuMkOkroEL5Kssks5sol31gaJpZM4PsYyC>
> .
>
|
where did you add this code? how can I call the method to send the string? |
when I draw the lines I can add text by these code otherwise the code is only for reference it can't be used without any changes because our project is different |
Can u please put swift version for this code.? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi... me again 😄
I want to ask you about how can I add text inside the lines with the distance between the start poing and the end point?
Can you help me?
Thanks
The text was updated successfully, but these errors were encountered: