Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To make label text as link

Tags:

ios

I have used "Register yourself" as text. I want to make it as link. And by clicking on that link, it should open Register.xib.

How can I get this link??

like image 605
Krunal Avatar asked Jan 04 '12 08:01

Krunal


2 Answers

Kareem is right. Create a UIButton object, set it's type to "Custom" and then you can give it a title. Connect the action to a method which pushes or presents your Register view controller and you will be all set.

You'll probably want to give some indication to the user that the text is a clickable link. Either set the color of the text to blue. Another, completely separate option, is to use a NSAttributedString (which has an underline attribute) to indicate to the user that the text is clickable. That requires an Open Source replacement for UITextView (which you can learn more about from this related question).

like image 101
Michael Dautermann Avatar answered Oct 03 '22 14:10

Michael Dautermann


I think by below you will get what you want...

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{   
    NSSet *allTouches = [event allTouches];
    if ([allTouches count] == 1)
    {
        UITouch *touch = (UITouch *)[allTouches anyObject];
        CGPoint touchPoint = [touch locationInView:self];

        // Convert to coordinate system of current view
        touchPoint.y -= self.bounds.size.height;
        touchPoint.y *= -1;

        CGPathRef statusPath = CTFrameGetPath(statusCTFrame);
        NSString *touchedInterStr = nil;
        if (CGPathContainsPoint(statusPath, NULL, touchPoint, FALSE))
        {
            touchedInterStr = [self getInteractiveStringInFrame:statusCTFrameatPosition:touchPoint];
        }
        else
        {
            return ;
        }
    }
}
like image 27
iTrained Avatar answered Oct 03 '22 13:10

iTrained