Posts

Showing posts from March, 2014

Hyperlinks in iOS App by detecting Links, Phone Number, Address and CalendarEvent in UITextView

Image
In many scenarios we have to detect Links(URLs) and Phone Numbers from given NSString and make it similar to hyperlink in HTML. Suppose you have a string with multiple url's and you want to make it clickable, so as to be able to open it in Safari browser. In below code i have taken a string which consists of two url's and i want to make it clickable. So i take a UITextView "txtViewClickableHyperLink" and assigned the NSString "strText" to it. Now i have used a magic line to setDataDetector of UITextView, this line has power to recognise my url. By changing type of DataDetector we can recognise: UIDataDetectorTypeLink                  - URL (Link) UIDataDetectorTypePhoneNumber   - Phone Number UIDataDetectorTypeAddress             - Address UIDataDetectorTypeCalendarEvent   - Calendar Event UIDataDetectorTypeAll                      - Detects all types NSString *strText = [NSString stringWithFormat: @" Hey this is my blog: http://objective

UIPanGestureRecognizer to create Screen similar to Notification Center

Image
In my application i wanted a Screen similar to the Notification Center of the iPhone. Where user can navigate through 3 screens using swipe gesture and also by selecting the UISegmentedControl index. So i have figured out below code.   -(void)viewDidLoad { [super viewDidLoad];   // I have added a ScrollView on Xib file of width 960px here. // added content(UIControls) required on first screen at 0px to 320px. // added content(UIControls) required on second screen at 320px to 640px. // added content(UIControls) required on third screen at 640px to 960px.   // I have added a UISegmentedControl on Xib file and set an action: - (IBAction)changeTab:(id)sender   // Add PangestureRecognizer to view    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeThroughTabs:)];    [panRecognizer setMinimumNumberOfTouches:1];    [panRecognizer setMaximumNumberOfTouches:1];    [panRecognizer setDelegate:self];    [self.view addGestureRecognize