UITextView *textView = [[UITextView alloc] init];
textView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:textView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />";
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
textView.attributedText = attributedString;
Friday, 4 April 2014
UITextView with HTML text
Monday, 31 March 2014
Fix blank space at top of UITextView in iOS 7
-(BOOL)automaticallyAdjustsScrollViewInsets{
return NO;
}
Saturday, 29 March 2014
Loading Table view Cell image form URL
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0) , ^{
NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"Image url here"]];
if (imgData) {
UIImage *image = [UIImage imageWithData:imgData];
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
MyCustomCell *cell = (id)[tableView cellForRowAtIndexPath:indexPath];
if (cell)
cell.myCellImgView.image=image;
});
}
}
});
Wednesday, 26 March 2014
@Property Attributes
| Attribute | Description |
|---|---|
getter= | Use a custom name for the getter method. |
setter= | Use a custom name for the setter method. |
readonly | Don’t synthesize a setter method. |
nonatomic | Don’t guarantee the integrity of accessors in a multi-threaded environment. This is more efficient than the default atomic behavior. |
strong | Create an owning relationship between the property and the assigned value. This is the default for object properties. |
weak | Create a non-owning relationship between the property and the assigned value. Use this to prevent retain cycles. |
copy | Create a copy of the assigned value instead of referencing the existing instance. Reference |
Monday, 24 March 2014
NULL and nil
- The null pointer is a special kind of pointer that doesn’t point to anything.
- Pointer can be “emptied” using the null pointer.
- A good rule of thumb is to use nil for variables that hold Objective-C objects and NULL when working with C pointers.
NSString *anObject; // An Objective-C object anObject = NULL; // This will work anObject = nil; // But this is preferred int *aPointer; // A plain old C pointer aPointer = nil; // Don't do this aPointer = NULL; // Do this instead
Monday, 3 March 2014
Find Longitude and Latitude From Address String
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
NSString *addressString =@"Apple Inc";
[geocoder
geocodeAddressString:addressString
completionHandler:^(NSArray *placemarks,
NSError *error) {
if (error) {
NSLog(@"Geocode failed with error: %@", error);
return;
}
if (placemarks && placemarks.count > 0)
{
CLPlacemark *placemark = placemarks[0];
CLLocation *location = placemark.location;
NSLog(@"latitude = %f longitude = %f",location.coordinate.latitude , location.coordinate.longitude);
}
}];
Location Details From latitude and longitude
CLLocation *location=[[CLLocation alloc] initWithLatitude:48.8582 longitude:2.2945];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if(placemarks.count){
NSDictionary *addressDictionary = [[placemarks objectAtIndex:0] addressDictionary];
NSLog(@"Address%@",addressDictionary);
}
}];
Subscribe to:
Posts (Atom)