Latest 100 public snipts »
nicolascormier's
snipts
showing 1-12 of 12 snipts
-
∞ vrac
- (UITableViewCell*) tableView:(UITableView*)target cellForRowAtIndexPath:(NSIndexPath*)indexPath { UITableViewCell* sourceCell = nil; NSInteger row = kIndexPathToRow(indexPath); if (!row) { static NSString* sCellID = @"EKArticlesListHeaderCell"; sourceCell = [target dequeueReusableCellWithIdentifier:sCellID]; if (!sourceCell) sourceCell = [[[EKArticlesListHeaderCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease]; } else if ((row-1) < [_articles count]) { static NSString* sCellID = @"EKArticlesListOptimizedCell"; sourceCell = [target dequeueReusableCellWithIdentifier:sCellID]; if (!sourceCell) sourceCell = [[[EKArticlesListOptimizedCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease]; ((EKArticlesListOptimizedCell*)sourceCell).article = [_articles objectAtIndex:(row-1)]; } else // load more row { static NSString* sCellID = @"EKArticlesMoreListCell"; sourceCell = [target dequeueReusableCellWithIdentifier:sCellID]; if (!sourceCell) sourceCell = [[[EKArticlesMoreListCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease]; ((EKArticlesMoreListCell*)sourceCell).current = _fetchLimit; ((EKArticlesMoreListCell*)sourceCell).total = _totalArticleCount; } return sourceCell; }
-
∞ vrac
- (id) initWithFrame:(CGRect)aRect reuseIdentifier:(NSString *)identifier { if (self = [super initWithFrame:aRect reuseIdentifier:identifier]) { self.selectionStyle = UITableViewCellSelectionStyleGray; _mybackgroundView = [[[UIView alloc] initWithFrame:aRect] autorelease]; _mybackgroundView.backgroundColor = [UIColor whiteColor]; [self.contentView addSubview:_mybackgroundView]; _titleLabel = [[[UILabel alloc] initWithFrame:aRect] autorelease]; _titleLabel.numberOfLines = 1; _titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16.]; _titleLabel.textColor = [UIColor colorWithRed:71./255. green:68./255. blue:58./255. alpha:1.]; _titleLabel.text = @"Load More Articles..."; [self.contentView addSubview:_titleLabel]; _subtitleLabel = [[[UILabel alloc] initWithFrame:aRect] autorelease]; _subtitleLabel.numberOfLines = 1; _subtitleLabel.font = [UIFont fontWithName:@"Arial" size:12.]; _subtitleLabel.textColor = [UIColor colorWithRed:119./255. green:119./255. blue:119./255. alpha:1.]; [self.contentView addSubview:_subtitleLabel]; } return self; } - (CGSize) layoutSubviewsThatFits:(CGSize)size setFrames:(BOOL)setFrames { CGSize titleTextSize = ((CGRect)[_titleLabel textRectForBounds:CGRectMake(0., 0., size.width, kBloodyHugeHeight) limitedToNumberOfLines:_titleLabel.numberOfLines]).size; CGSize subtitleTextSize = ((CGRect)[_subtitleLabel textRectForBounds:CGRectMake(0., 0., size.width, kBloodyHugeHeight) limitedToNumberOfLines:_subtitleLabel.numberOfLines]).size; CGFloat maxHeight = titleTextSize.height + subtitleTextSize.height + kTopMargin + kBottomMargin + kElementPadding; CGRect titleFrame = CGRectMake(size.width/2. - titleTextSize.width/2., maxHeight/2. - (titleTextSize.height+subtitleTextSize.height)/2., titleTextSize.width, titleTextSize.height); CGRect subtitleFrame = CGRectMake(size.width/2. - subtitleTextSize.width/2., titleFrame.origin.y + titleTextSize.height + kElementPadding, subtitleTextSize.width, subtitleTextSize.height); if (setFrames) { _titleLabel.frame = CSNormalizeFrame(titleFrame); _subtitleLabel.frame = CSNormalizeFrame(subtitleFrame); _mybackgroundView.frame = CGRectMake(0., 0., size.width, size.height); } return ((CGSize){ size.width, maxHeight }); } - (CGSize) sizeThatFits:(CGSize)size { return [self layoutSubviewsThatFits:size setFrames:NO]; } - (void) layoutSubviews { [super layoutSubviews]; (void) [self layoutSubviewsThatFits:self.bounds.size setFrames:YES]; }
-
∞ vrac
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; _navigationController = [[UINavigationController alloc] initWithRootViewController:[[[HLHomepageListViewController alloc] init] autorelease]]; [_window addSubview:_navigationController.view]; [self performSelectorInBackground:@selector(forceMobileVersion) withObject:nil]; - (void) forceMobileVersion { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [NSData dataWithContentsOfURL:[HLConstants forceMobileVersionOfWebsiteURL]]; [pool release]; }
-
∞ random md5
md5(uniqid(rand(), true)); -
∞ view fade animation
CATransition* animation = [CATransition animation]; [animation setType:kCATransitionFade]; [[aSuperview layer] addAnimation:animation forKey:@"layerAnimation"];
-
∞ class initialiser
+ (void) initialize { if (self == [ClassName class]) { /** * initialize class properties */ } }
-
∞ uiview to uiimage
UIGraphicsBeginImageContext(myView.bounds.size); [myView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
-
∞ sql force id insert
SET IDENTITY_INSERT TABLE ON; INSERT INTO TABLE (ID, ...) VALUES (ID, ...); SET IDENTITY_INSERT TABLE OFF;
-
∞ shadow gradient
- (CAGradientLayer *)shadowAsInverse:(BOOL)inverse { CAGradientLayer *newShadow = [[[CAGradientLayer alloc] init] autorelease]; CGRect newShadowFrame = CGRectMake(0, 0, self.frame.size.width, inverse ? SHADOW_INVERSE_HEIGHT : SHADOW_HEIGHT); newShadow.frame = newShadowFrame; CGColorRef darkColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha: inverse ? (SHADOW_INVERSE_HEIGHT / SHADOW_HEIGHT) * 0.5 : 0.5].CGColor; CGColorRef lightColor = [self.backgroundColor colorWithAlphaComponent:0.0].CGColor; newShadow.colors = [NSArray arrayWithObjects:(id)(inverse ? lightColor : darkColor), (id)(inverse ? darkColor : lightColor), nil]; return newShadow; }
-
∞ modx menu generator
<?php $pages = $modx->getAllChildren($modx->documentObject['id'], $sort= 'menuindex', $dir= 'ASC', $fields= 'id, pagetitle, introtext'); ?> <? foreach ($pages as $page): ?> <li><a href="<?=$modx->makeUrl($page['id'])?>"><?=$page['pagetitle']?></a> </li> <? endforeach ?>
-
∞ uitableview variable height
- (CGFloat) tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath { return ((CGSize)[[self tableView:tableView cellForRowAtIndexPath:indexPath] sizeThatFits:self.view.frame.size]).height; } - (NSInteger) numberOfSectionsInTableView:(UITableView*)tableView { return 1; } - (NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell*) tableView:(UITableView*)target cellForRowAtIndexPath:(NSIndexPath*)indexPath { static NSString* sCellID = @"HLAskListCell"; UITableViewCell* sourceCell = [target dequeueReusableCellWithIdentifier:sCellID]; if (!sourceCell) sourceCell = [[[HLAskListCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease]; return sourceCell; }
-
∞ layoutSubviewsThatFits
CGSize titleTextSize = ((CGRect)[_titleLabel textRectForBounds:CGRectMake(contentLeftOffset, topOffset, contentWidth, kBloodyHugeHeight) limitedToNumberOfLines:_titleLabel.numberOfLines]).size; CGRect titleFrame = CGRectMake(contentLeftOffset, topOffset, contentWidth, titleTextSize.height); topOffset += titleFrame.size.height + kTitleBottomPadding;


