Resize UIImage
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Labels:
change,
image,
iphone SDK,
size
API to get current Address
http://maps.googleapis.com/maps/api/geocode/json?latlng=1.298564,103.853973&sensor=false
UIButton Edge Inset
CGFloat spacing = 10; // the amount of spacing to appear between image and title
tabBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, spacing);
tabBtn.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
Labels:
button,
edge,
inset,
iphone SDK
Scroll Tableview to the top
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
Labels:
bottom,
iphone SDK,
table
Get Youtube Video ID
+ (NSString*) getVideoID:(NSString*)linkString
{
NSMutableString *predicateString = [[NSMutableString alloc] initWithFormat:@"%@", linkString];
NSString *regexStr = @"[a-zA-Z0-9_-]{10}";
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr
options:NSRegularExpressionCaseInsensitive
error:&error];
__block NSString *retunString = @"";
[regex enumerateMatchesInString:predicateString options:0 range:NSMakeRange(0, [predicateString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
NSRange matchRange = [match range];
matchRange.length = matchRange.length+1;
//NSLog(@"matchRange.location: %d",matchRange.location); //31
//NSLog(@"matchRange.length: %d",matchRange.length); //11
//NSLog(@"result: %@", [predicateString substringWithRange:matchRange]); //tTfj05VNT40
retunString = [predicateString substringWithRange:matchRange];
}];
return retunString;
}
Labels:
iphone SDK,
regex
Make a UIImage from a MKMapView or Other View
The improved function for retina display:
- (UIImage*) renderToImage
{
if(UIGraphicsBeginImageContextWithOptions != NULL)
{
UIGraphicsBeginImageContextWithOptions(mapView.frame.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(mapView.frame.size);
}
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
UITextField align left margin and clear button
you can do it by overriding two methods:
- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;
the first one to align the placeholder and the second one for the editable text, so here is the code following your first answer
@implementation MYTextField
- (CGRect)textRectForBounds:(CGRect)bounds {
CGRect inset = CGRectMake(bounds.origin.x + 10, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
return inset;
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
CGRect inset = CGRectMake(bounds.origin.x + 10, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
return inset;
}
- (CGRect)clearButtonRectForBounds:(CGRect)bounds {
CGRect inset = CGRectMake(bounds.origin.x + 113, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
return inset;
}
Subscribe to:
Posts (Atom)