Skip to content

Instantly share code, notes, and snippets.

View maninp's full-sized avatar

Manikandan M maninp

View GitHub Profile
@maninp
maninp / GoogleImageFilePath.java
Created May 23, 2017 06:12 — forked from SeongUgJung/GoogleImageFilePath.java
Android Google Photos's Uri
public String getImagePath(Context context, Uri uri){
if ("content".equalsIgnoreCase(uri.getScheme())) {
if (isGoogleOldPhotosUri(uri)) {
// return http path, then download file.
return uri.getLastPathSegment();
} else if (isGoogleNewPhotosUri(uri)) {
// copy from uri. context.getContentResolver().openInputStream(uri);
return copyFile(context, uri);
} else if (isPicasaPhotoUri(uri)) {
Project # of Top 100 Free Apps (US)
facebook-ios-sdk 67
Bolts-iOS 48
AFNetworking 39
Google-Mobile-Ads-SDK 38
Reachability (Apple) 38
Crashlytics 37
Flurry-iOS-SDK 31
CocoaPods 30
GoogleConversionTracking 29
- (CGRect)getMaxFrameForText:(UILabel *)label {
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
CGRect currentFrame = label.frame;
CGSize max = CGSizeMake(label.frame.size.width, 250);
CGRect textRect = [label.text boundingRectWithSize:max options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil];
currentFrame.size.height = ceilf(textRect.size.height);
return currentFrame;
}
- (CGFloat)heightOfCellWithIngredientLine:(NSString *)ingredientLine maxSize:(CGSize)max labelFont:(UIFont*)font
{
NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
CGRect labelRect = [ingredientLine boundingRectWithSize:max
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:font}
context:context];
//
// UILabel+OKASizeCalculator.m
//
// Created by Oliver on 16/01/2014.
// Copyright (c) 2014 Oliver Atkinson. All rights reserved.
//
#import "UILabel+OKASizeCalculator.h"
@implementation UILabel (OKASizeCalculator)
- (CGSize)intrinsicContentSize {
CGSize boundingSize = CGSizeMake(self.titleLabel.preferredMaxLayoutWidth - self.titleEdgeInsets.left - self.titleEdgeInsets.right, CGFLOAT_MAX);
NSAttributedString *attributedTitle = [self attributedTitleForState:self.state];
CGRect boundingRect;
if(attributedTitle) {
- (CGFloat)heighWithFont:(UIFont *)font constrainedToSize:(CGSize)size
{
return [self sizeWithFont:font constrainedToSize:size].height;
}
- (CGFloat)widthWithFont:(UIFont *)font constrainedToSize:(CGSize)size
{
return [self sizeWithFont:font constrainedToSize:size].width;
}
NSString *str = <#some string#>;
CGSize size;
CGSize maxSize = CGSizeMake(<#width#>, <#height#>);
UIFont *font = <#font#>;
if ([str respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setLineBreakMode:<#Line break mode#>];
[style setAlignment:<#String alignment#>];
NSDictionary *attributes = @{ NSFontAttributeName:font,
NSParagraphStyleAttributeName:style
+ (CGFloat) estimateHeight:(NSString *)content{
NSAttributedString *bodyText = [NSAttributedString attributedStringWithMarkdownString:content font:MYCellFontDefine];
CGRect rect = [bodyText boundingRectWithSize:CGSizeMake(CELL_WIDTH, FLT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];
return CGRectGetHeight(rect);
}
CGSize maximumLabelSize = CGSizeMake(tableView.width, MAXFLOAT);
NSStringDrawingOptions options = NSStringDrawingTruncatesLastVisibleLine |
NSStringDrawingUsesLineFragmentOrigin;
NSDictionary *attr = @{NSFontAttributeName: [UIFont systemFontOfSize:15]};
CGRect labelBounds = [string boundingRectWithSize:maximumLabelSize
options:options
attributes:attr
context:nil];